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