@@ -1791,7 +1791,7 @@ class Namer { typer: Typer =>
1791
1791
sym.owner.typeParams.foreach(_.ensureCompleted())
1792
1792
completeTrailingParamss(constr, sym, indexingCtor = true )
1793
1793
if Feature .enabled(modularity) then
1794
- constr.termParamss.foreach(_.foreach(setTracked ))
1794
+ constr.termParamss.foreach(_.foreach(setTrackedConstrParam ))
1795
1795
1796
1796
/** The signature of a module valdef.
1797
1797
* This will compute the corresponding module class TypeRef immediately
@@ -1935,10 +1935,8 @@ class Namer { typer: Typer =>
1935
1935
for params <- ddef.termParamss; param <- params do
1936
1936
val psym = symbolOfTree(param)
1937
1937
if needsTracked(psym, param, owningSym) then
1938
- for acc <- sym.maybeOwner.infoOrCompleter.decls.lookupAll(psym.name) if acc.is(ParamAccessor ) do
1939
- acc.resetFlag(PrivateLocal )
1940
- psym.setFlag(Tracked )
1941
- acc.setFlag(Tracked )
1938
+ psym.setFlag(Tracked )
1939
+ setParamTrackedWithAccessors(psym, sym.maybeOwner.infoOrCompleter)
1942
1940
1943
1941
if Feature .enabled(modularity) then addTrackedIfNeeded(ddef, sym.maybeOwner)
1944
1942
@@ -1999,8 +1997,15 @@ class Namer { typer: Typer =>
1999
1997
cls.srcPos)
2000
1998
case _ =>
2001
1999
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
2000
+ private def setParamTrackedWithAccessors (psym : Symbol , ownerTpe : Type )(using Context ): Unit =
2001
+ for acc <- ownerTpe.decls.lookupAll(psym.name) if acc.is(ParamAccessor ) do
2002
+ acc.resetFlag(PrivateLocal )
2003
+ psym.setFlag(Tracked )
2004
+ acc.setFlag(Tracked )
2005
+
2006
+ /** `psym` needs tracked if it is referenced in any of the public signatures
2007
+ * of the defining class or when `psym` is a context bound witness with an
2008
+ * abstract type member
2004
2009
*/
2005
2010
def needsTracked (psym : Symbol , param : ValDef , owningSym : Symbol )(using Context ) =
2006
2011
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
@@ -2014,24 +2019,25 @@ class Namer { typer: Typer =>
2014
2019
|| isRefInSignatures
2015
2020
)
2016
2021
2017
- /** Under x.modularity, we add `tracked` to context bound witnesses
2018
- * that have abstract type members
2022
+ /** Under x.modularity, we add `tracked` to context bound witnesses and
2023
+ * explicit evidence parameters that have abstract type members
2019
2024
*/
2020
- def isContextBoundWitnessWithAbstractMembers (psym : Symbol , param : ValDef , owningSym : Symbol )(using Context ): Boolean =
2025
+ private def isContextBoundWitnessWithAbstractMembers (psym : Symbol , param : ValDef , owningSym : Symbol )(using Context ): Boolean =
2026
+ val accessorSyms = maybeParamAccessors(owningSym, psym)
2021
2027
(owningSym.isClass || owningSym.isAllOf(Given | Method ))
2022
- && (param.hasAttachment(ContextBoundParam ) || psym.isOneOf(GivenOrImplicit ))
2028
+ && (param.hasAttachment(ContextBoundParam ) || ( psym.isOneOf(GivenOrImplicit ) && ! accessorSyms.forall(_.isOneOf( PrivateLocal )) ))
2023
2029
&& psym.info.memberNames(abstractTypeNameFilter).nonEmpty
2024
2030
2025
2031
extension (sym : Symbol )
2026
- def infoWithForceNonInferingCompleter (using Context ): Type = sym.infoOrCompleter match
2032
+ private def infoWithForceNonInferingCompleter (using Context ): Type = sym.infoOrCompleter match
2027
2033
case tpe : LazyType if tpe.isNonInfering => sym.info
2028
2034
case tpe if sym.isType => sym.info
2029
2035
case info => info
2030
2036
2031
- /** Under x.modularity, we add `tracked` to term parameters whose types are referenced
2032
- * in public signatures of the defining class
2037
+ /** Under x.modularity, we add `tracked` to term parameters whose types are
2038
+ * referenced in public signatures of the defining class
2033
2039
*/
2034
- def isReferencedInPublicSignatures (sym : Symbol )(using Context ): Boolean =
2040
+ private def isReferencedInPublicSignatures (sym : Symbol )(using Context ): Boolean =
2035
2041
val owner = sym.maybeOwner.maybeOwner
2036
2042
val accessorSyms = maybeParamAccessors(owner, sym)
2037
2043
def checkOwnerMemberSignatures (owner : Symbol ): Boolean =
@@ -2061,20 +2067,18 @@ class Namer { typer: Typer =>
2061
2067
info.decls.lookupAll(sym.name).filter(d => d.is(ParamAccessor )).toList
2062
2068
case _ => List (sym)
2063
2069
2064
- /** Under x.modularity, set every context bound evidence parameter of a class to be tracked,
2065
- * provided it has a type that has an abstract type member. Reset private and local flags
2066
- * so that the parameter becomes a `val`.
2070
+ /** Under x.modularity, set every context bound evidence parameter or public
2071
+ * using parameter of a class to be tracked, provided it has a type that has
2072
+ * an abstract type member. Reset private and local flags so that the
2073
+ * parameter becomes a `val`.
2067
2074
*/
2068
- def setTracked (param : ValDef )(using Context ): Unit =
2075
+ def setTrackedConstrParam (param : ValDef )(using Context ): Unit =
2069
2076
val sym = symbolOfTree(param)
2070
2077
sym.maybeOwner.maybeOwner.infoOrCompleter match
2071
2078
case info : ClassInfo
2072
2079
if ! sym.is(Tracked ) && isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner) =>
2073
2080
typr.println(i " set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}" )
2074
- for acc <- info.decls.lookupAll(sym.name) if acc.is(ParamAccessor ) do
2075
- acc.resetFlag(PrivateLocal )
2076
- acc.setFlag(Tracked )
2077
- sym.setFlag(Tracked )
2081
+ setParamTrackedWithAccessors(sym, info)
2078
2082
case _ =>
2079
2083
2080
2084
def inferredResultType (
0 commit comments