Skip to content

Commit 7142e3d

Browse files
committed
Fix some pickling errors •ᴗ•
1 parent ee0c24e commit 7142e3d

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Namer.scala

+18-11
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ 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")
17941795
constr.termParamss.foreach(_.foreach(setTracked))
17951796

17961797
/** The signature of a module valdef.
@@ -1931,22 +1932,26 @@ class Namer { typer: Typer =>
19311932
def wrapRefinedMethType(restpe: Type): Type =
19321933
wrapMethType(addParamRefinements(restpe, paramSymss))
19331934

1935+
def addTrackedIfNeeded(ddef: DefDef, owningSym: Symbol): Boolean =
1936+
var wasSet = false
1937+
for params <- ddef.termParamss; param <- params do
1938+
val psym = symbolOfTree(param)
1939+
if needsTracked(psym, param, owningSym) then
1940+
psym.setFlag(Tracked)
1941+
wasSet = true
1942+
wasSet
1943+
1944+
if Feature.enabled(modularity) then addTrackedIfNeeded(ddef, sym.maybeOwner)
1945+
19341946
if isConstructor then
19351947
// set result type tree to unit, but take the current class as result type of the symbol
19361948
typedAheadType(ddef.tpt, defn.UnitType)
19371949
val mt = wrapMethType(effectiveResultType(sym, paramSymss))
19381950
if sym.isPrimaryConstructor then checkCaseClassParamDependencies(mt, sym.owner)
19391951
mt
1940-
else if Feature.enabled(modularity) then
1941-
// set every context bound evidence parameter of a given companion method
1942-
// to be tracked, provided it has a type that has an abstract type member.
1943-
// Add refinements for all tracked parameters to the result type.
1944-
for params <- ddef.termParamss; param <- params do
1945-
val psym = symbolOfTree(param)
1946-
if needsTracked(psym, param, sym) then psym.setFlag(Tracked)
1947-
valOrDefDefSig(ddef, sym, paramSymss, wrapRefinedMethType)
19481952
else
1949-
valOrDefDefSig(ddef, sym, paramSymss, wrapMethType)
1953+
val paramFn = if Feature.enabled(Feature.modularity) && sym.isAllOf(Given | Method) then wrapRefinedMethType else wrapMethType
1954+
valOrDefDefSig(ddef, sym, paramSymss, paramFn)
19501955
end defDefSig
19511956

19521957
/** Complete the trailing parameters of a DefDef,
@@ -1998,6 +2003,7 @@ class Namer { typer: Typer =>
19982003
/** Try to infer if the parameter needs a `tracked` modifier
19992004
*/
20002005
def needsTracked(psym: Symbol, param: ValDef, owningSym: Symbol)(using Context) =
2006+
// println(i"Checking if $psym needs tracked")
20012007
lazy val abstractContextBound = isContextBoundWitnessWithAbstractMembers(psym, param, owningSym)
20022008
lazy val isRefInSignatures =
20032009
psym.maybeOwner.isPrimaryConstructor
@@ -2071,8 +2077,9 @@ class Namer { typer: Typer =>
20712077
def setTracked(param: ValDef)(using Context): Unit =
20722078
val sym = symbolOfTree(param)
20732079
sym.maybeOwner.maybeOwner.infoOrCompleter match
2074-
case info: ClassInfo if needsTracked(sym, param, sym.maybeOwner.maybeOwner) =>
2075-
typr.println(i"set tracked $param, $sym: ${sym.info} containing ${sym.info.memberNames(abstractTypeNameFilter).toList}")
2080+
case info: ClassInfo
2081+
if !sym.is(Tracked) && isContextBoundWitnessWithAbstractMembers(sym, param, sym.maybeOwner.maybeOwner) =>
2082+
typr.println(i"set tracked $param, $sym: ${sym.info}")
20762083
for acc <- info.decls.lookupAll(sym.name) if acc.is(ParamAccessor) do
20772084
acc.resetFlag(PrivateLocal)
20782085
acc.setFlag(Tracked)

Diff for: compiler/test/dotc/pos-test-pickling.blacklist

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ parsercombinators-new-syntax.scala
135135
hylolib-deferred-given
136136
hylolib-cb
137137
hylolib
138+
infer-tracked-parsercombinators-givens.scala
138139

139140
# typecheckErrors method unpickling
140141
i21415.scala

Diff for: tests/pos/infer-tracked-parent-refinements.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.language.experimental.modularity
2+
import scala.language.future
3+
4+
trait WithValue { type Value = Int }
5+
6+
case class Year(value: Int) extends WithValue {
7+
val x: Value = 2
8+
}

Diff for: tests/pos/infer-tracked-parsercombinators-givens.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import scala.language.experimental.modularity
22
import scala.language.future
3-
43
import collection.mutable
54

65
/// A parser combinator.
@@ -19,7 +18,7 @@ end Combinator
1918
final case class Apply[C, E](action: C => Option[E])
2019
final case class Combine[A, B](first: A, second: B)
2120

22-
given apply[C, E]: Combinator[Apply[C, E]] with {
21+
given apply: [C, E] => Combinator[Apply[C, E]] {
2322
type Context = C
2423
type Element = E
2524
extension(self: Apply[C, E]) {

0 commit comments

Comments
 (0)