Skip to content

Commit d67a070

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 645b0f3 commit d67a070

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
@@ -4860,7 +4860,7 @@ object Types {
48604860
}
48614861
}
48624862

4863-
abstract class TypeMap(implicit protected val mapCtx: Context)
4863+
abstract class TypeMap(implicit protected var mapCtx: Context)
48644864
extends VariantTraversal with (Type => Type) { thisMap =>
48654865

48664866
protected def stopAtStatic: Boolean = true
@@ -4977,7 +4977,12 @@ object Types {
49774977
derivedSuperType(tp, this(thistp), this(supertp))
49784978

49794979
case tp: LazyRef =>
4980-
LazyRef(_ => this(tp.ref))
4980+
LazyRef { c =>
4981+
val saved = mapCtx
4982+
mapCtx = c
4983+
try this(tp.ref(using c))
4984+
finally mapCtx = saved
4985+
}
49814986

49824987
case tp: ClassInfo =>
49834988
mapClassInfo(tp)

0 commit comments

Comments
 (0)