Skip to content

Commit 61b8eed

Browse files
committed
Avoid time travel when handling of LazyRefs
The idea of LazyRefs is that they are always completed in the current context. But that did not work if the LazyRef is mapped in a type map. Here, the TypeMap's context was used to do the remap. We now use the context that forced the LazyVal instead. The problem manifested itself with failing replTests when the new implicitScope scheme was used.
1 parent b852e14 commit 61b8eed

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class TypeApplications(val self: Type) extends AnyVal {
337337
case dealiased: TypeBounds =>
338338
dealiased.derivedTypeBounds(dealiased.lo.appliedTo(args), dealiased.hi.appliedTo(args))
339339
case dealiased: LazyRef =>
340-
LazyRef(c => dealiased.ref(c).appliedTo(args))
340+
LazyRef(c => dealiased.ref(c).appliedTo(args)(using c))
341341
case dealiased: WildcardType =>
342342
WildcardType(dealiased.optBounds.orElse(TypeBounds.empty).appliedTo(args).bounds)
343343
case dealiased: TypeRef if dealiased.symbol == defn.NothingClass =>

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,7 +4862,7 @@ object Types {
48624862
}
48634863
}
48644864

4865-
abstract class TypeMap(implicit protected val mapCtx: Context)
4865+
abstract class TypeMap(implicit protected var mapCtx: Context)
48664866
extends VariantTraversal with (Type => Type) { thisMap =>
48674867

48684868
protected def stopAtStatic: Boolean = true
@@ -4979,7 +4979,12 @@ object Types {
49794979
derivedSuperType(tp, this(thistp), this(supertp))
49804980

49814981
case tp: LazyRef =>
4982-
LazyRef(_ => this(tp.ref))
4982+
LazyRef { c =>
4983+
val saved = mapCtx
4984+
mapCtx = c
4985+
try this(tp.ref(using c))
4986+
finally mapCtx = saved
4987+
}
49834988

49844989
case tp: ClassInfo =>
49854990
mapClassInfo(tp)

0 commit comments

Comments
 (0)