@@ -1885,6 +1885,28 @@ class Namer { typer: Typer =>
1885
1885
ddef.trailingParamss.foreach(completeParams)
1886
1886
val paramSymss = normalizeIfConstructor(ddef.paramss.nestedMap(symbolOfTree), isConstructor)
1887
1887
sym.setParamss(paramSymss)
1888
+
1889
+ /** We add `tracked` to context bound witnesses that have abstract type members */
1890
+ def needsTracked (sym : Symbol , param : ValDef )(using Context ) =
1891
+ ! sym.is(Tracked )
1892
+ && param.hasAttachment(ContextBoundParam )
1893
+ && sym.info.memberNames(abstractTypeNameFilter).nonEmpty
1894
+
1895
+ /** Set every context bound evidence parameter of a class to be tracked,
1896
+ * provided it has a type that has an abstract type member. Reset private and local flags
1897
+ * so that the parameter becomes a `val`.
1898
+ */
1899
+ def setTracked (param : ValDef ): Unit =
1900
+ val sym = symbolOfTree(param)
1901
+ sym.maybeOwner.maybeOwner.infoOrCompleter match
1902
+ case info : TempClassInfo if needsTracked(sym, param) =>
1903
+ typr.println(i " set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}" )
1904
+ for acc <- info.decls.lookupAll(sym.name) if acc.is(ParamAccessor ) do
1905
+ acc.resetFlag(PrivateLocal )
1906
+ acc.setFlag(Tracked )
1907
+ sym.setFlag(Tracked )
1908
+ case _ =>
1909
+
1888
1910
def wrapMethType (restpe : Type ): Type =
1889
1911
instantiateDependent(restpe, paramSymss)
1890
1912
methodType(paramSymss, restpe, ddef.mods.is(JavaDefined ))
@@ -1893,10 +1915,18 @@ class Namer { typer: Typer =>
1893
1915
wrapMethType(addParamRefinements(restpe, paramSymss))
1894
1916
1895
1917
if isConstructor then
1918
+ if sym.isPrimaryConstructor && Feature .enabled(modularity) then
1919
+ ddef.termParamss.foreach(_.foreach(setTracked))
1896
1920
// set result type tree to unit, but take the current class as result type of the symbol
1897
1921
typedAheadType(ddef.tpt, defn.UnitType )
1898
1922
wrapMethType(effectiveResultType(sym, paramSymss))
1899
1923
else if sym.isAllOf(Given | Method ) && Feature .enabled(modularity) then
1924
+ // set every context bound evidence parameter of a given companion method
1925
+ // to be tracked, provided it has a type that has an abstract type member.
1926
+ // Add refinements for all tracked parameters to the result type.
1927
+ for params <- ddef.termParamss; param <- params do
1928
+ val psym = symbolOfTree(param)
1929
+ if needsTracked(psym, param) then psym.setFlag(Tracked )
1900
1930
valOrDefDefSig(ddef, sym, paramSymss, wrapRefinedMethType)
1901
1931
else
1902
1932
valOrDefDefSig(ddef, sym, paramSymss, wrapMethType)
0 commit comments