Skip to content

Commit 161f697

Browse files
committed
Also check type members, when infering tracked
1 parent 5c08c56 commit 161f697

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,6 @@ class Namer { typer: Typer =>
17911791
sym.owner.typeParams.foreach(_.ensureCompleted())
17921792
completeTrailingParamss(constr, sym, indexingCtor = true)
17931793
if Feature.enabled(modularity) then
1794-
// println(i"[indexConstructor] Checking if params of $constr need tracked")
17951794
constr.termParamss.foreach(_.foreach(setTracked))
17961795

17971796
/** The signature of a module valdef.
@@ -2000,7 +1999,8 @@ class Namer { typer: Typer =>
20001999
cls.srcPos)
20012000
case _ =>
20022001

2003-
/** Try to infer if the parameter needs a `tracked` modifier
2002+
/** `psym` needs tracked if it is referenced in any of the public signatures of the defining class
2003+
* or when `psym` is a context bound witness with an abstract type member
20042004
*/
20052005
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
20062006
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
@@ -2025,6 +2025,7 @@ class Namer { typer: Typer =>
20252025
extension (sym: Symbol)
20262026
def infoWithForceNonInferingCompleter(using Context): Type = sym.infoOrCompleter match
20272027
case tpe: LazyType if tpe.isNonInfering => sym.info
2028+
case tpe if sym.isType => sym.info
20282029
case info => info
20292030

20302031
/** Under x.modularity, we add `tracked` to term parameters whose types are referenced
@@ -2036,9 +2037,11 @@ class Namer { typer: Typer =>
20362037
def checkOwnerMemberSignatures(owner: Symbol): Boolean =
20372038
owner.infoOrCompleter match
20382039
case info: ClassInfo =>
2039-
info.decls.filter(_.isTerm).filter(_.isPublic)
2040+
info.decls.filter(_.isPublic)
20402041
.filter(_ != sym.maybeOwner)
2041-
.exists(d => tpeContainsSymbolRef(d.infoWithForceNonInferingCompleter, accessorSyms))
2042+
.exists { decl =>
2043+
tpeContainsSymbolRef(decl.infoWithForceNonInferingCompleter, accessorSyms)
2044+
}
20422045
case _ => false
20432046
checkOwnerMemberSignatures(owner)
20442047

@@ -2056,7 +2059,7 @@ class Namer { typer: Typer =>
20562059
private def maybeParamAccessors(owner: Symbol, sym: Symbol)(using Context): List[Symbol] = owner.infoOrCompleter match
20572060
case info: ClassInfo =>
20582061
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor)).toList
2059-
case _ => List.empty
2062+
case _ => List(sym)
20602063

20612064
/** Under x.modularity, set every context bound evidence parameter of a class to be tracked,
20622065
* provided it has a type that has an abstract type member. Reset private and local flags

tests/pos/infer-tracked.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ case class J(c: C):
2222
case class K(c: C):
2323
def result[B >: c.T]: B = c.foo
2424

25+
case class L(c: C):
26+
type T = c.T
27+
2528
def Test =
2629
val c = new C:
2730
type T = Int
@@ -44,3 +47,6 @@ def Test =
4447

4548
val k = K(c)
4649
val _: Int = k.result
50+
51+
val l = L(c)
52+
summon[l.T =:= Int]

0 commit comments

Comments
 (0)