@@ -30,6 +30,7 @@ import config.Feature.{sourceVersion, modularity}
3030import config .SourceVersion .*
3131
3232import scala .compiletime .uninitialized
33+ import dotty .tools .dotc .transform .init .Util .tree
3334
3435/** This class creates symbols from definitions and imports and gives them
3536 * lazy types.
@@ -1648,7 +1649,6 @@ class Namer { typer: Typer =>
16481649 * as an attachment on the ClassDef tree.
16491650 */
16501651 def enterParentRefinementSyms (refinements : List [(Name , Type )]) =
1651- println(s " For class $cls, entering parent refinements: $refinements" )
16521652 val refinedSyms = mutable.ListBuffer [Symbol ]()
16531653 for (name, tp) <- refinements do
16541654 if decls.lookupEntry(name) == null then
@@ -1658,7 +1658,6 @@ class Namer { typer: Typer =>
16581658 case _ => Synthetic | Deferred
16591659 val s = newSymbol(cls, name, flags, tp, coord = original.rhs.span.startPos).entered
16601660 refinedSyms += s
1661- println(s " entered $s" )
16621661 if refinedSyms.nonEmpty then
16631662 typr.println(i " parent refinement symbols: ${refinedSyms.toList}" )
16641663 original.pushAttachment(ParentRefinements , refinedSyms.toList)
@@ -1996,10 +1995,11 @@ class Namer { typer: Typer =>
19961995 */
19971996 def needsTracked (sym : Symbol , param : ValDef )(using Context ) =
19981997 ! sym.is(Tracked )
1998+ && sym.maybeOwner.isConstructor
19991999 && (
20002000 isContextBoundWitnessWithAbstractMembers(sym, param)
20012001 || isReferencedInPublicSignatures(sym)
2002- // || isPassedToTrackedParentParameter(sym, param)
2002+ || isPassedToTrackedParentParameter(sym, param)
20032003 )
20042004
20052005 /** Under x.modularity, we add `tracked` to context bound witnesses
@@ -2018,11 +2018,14 @@ class Namer { typer: Typer =>
20182018 def checkOwnerMemberSignatures (owner : Symbol ): Boolean =
20192019 owner.infoOrCompleter match
20202020 case info : ClassInfo =>
2021- info.decls.filter(d => ! d.isConstructor).exists(d => tpeContainsSymbolRef(d.info, accessorSyms))
2021+ info.decls.filter(_.isTerm)
2022+ .filter(_ != sym.maybeOwner)
2023+ .exists(d => tpeContainsSymbolRef(d.info, accessorSyms))
20222024 case _ => false
20232025 checkOwnerMemberSignatures(owner)
20242026
20252027 def isPassedToTrackedParentParameter (sym : Symbol , param : ValDef )(using Context ): Boolean =
2028+ // TODO(kπ) Add tracked if the param is passed as a tracked arg in parent. Can we touch the inheritance terms?
20262029 val owner = sym.maybeOwner.maybeOwner
20272030 val accessorSyms = maybeParamAccessors(owner, sym)
20282031 owner.infoOrCompleter match
@@ -2035,10 +2038,18 @@ class Namer { typer: Typer =>
20352038 case tpe : NamedType => tpe.prefix.exists && tpeContainsSymbolRef(tpe.prefix, syms)
20362039 case _ => false
20372040
2038- private def tpeContainsSymbolRef (tpe : Type , syms : List [Symbol ])(using Context ): Boolean =
2039- tpe.termSymbol.exists && syms.contains(tpe.termSymbol)
2040- || tpe.argInfos.exists(tpeContainsSymbolRef(_, syms))
2041- || namedTypeWithPrefixContainsSymbolRef(tpe, syms)
2041+ private def tpeContainsSymbolRef (tpe0 : Type , syms : List [Symbol ])(using Context ): Boolean =
2042+ val tpe = tpe0.dropAlias.widenExpr.dealias
2043+ tpe match
2044+ case m : MethodOrPoly =>
2045+ m.paramInfos.exists(tpeContainsSymbolRef(_, syms))
2046+ || tpeContainsSymbolRef(m.resultType, syms)
2047+ case r @ RefinedType (parent, _, refinedInfo) => tpeContainsSymbolRef(parent, syms) || tpeContainsSymbolRef(refinedInfo, syms)
2048+ case TypeBounds (lo, hi) => tpeContainsSymbolRef(lo, syms) || tpeContainsSymbolRef(hi, syms)
2049+ case t : Type =>
2050+ tpe.termSymbol.exists && syms.contains(tpe.termSymbol)
2051+ || tpe.argInfos.exists(tpeContainsSymbolRef(_, syms))
2052+ || namedTypeWithPrefixContainsSymbolRef(tpe, syms)
20422053
20432054 private def maybeParamAccessors (owner : Symbol , sym : Symbol )(using Context ): List [Symbol ] =
20442055 owner.infoOrCompleter match
0 commit comments