diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index f66e9f35fae2..12ea35ba1c62 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -337,7 +337,7 @@ class TypeApplications(val self: Type) extends AnyVal { case dealiased: TypeBounds => dealiased.derivedTypeBounds(dealiased.lo.appliedTo(args), dealiased.hi.appliedTo(args)) case dealiased: LazyRef => - LazyRef(c => dealiased.ref(c).appliedTo(args)) + LazyRef(c => dealiased.ref(c).appliedTo(args)(using c)) case dealiased: WildcardType => WildcardType(dealiased.optBounds.orElse(TypeBounds.empty).appliedTo(args).bounds) case dealiased: TypeRef if dealiased.symbol == defn.NothingClass => diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 9aa181bd2b02..e94ea2388ab2 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4862,7 +4862,7 @@ object Types { } } - abstract class TypeMap(implicit protected val mapCtx: Context) + abstract class TypeMap(implicit protected var mapCtx: Context) extends VariantTraversal with (Type => Type) { thisMap => protected def stopAtStatic: Boolean = true @@ -4979,7 +4979,16 @@ object Types { derivedSuperType(tp, this(thistp), this(supertp)) case tp: LazyRef => - LazyRef(_ => this(tp.ref)) + LazyRef { c => + val ref1 = tp.ref(using c) + if c.runId == mapCtx.runId then this(ref1) + else // splice in new run into map context + val saved = mapCtx + mapCtx = mapCtx.fresh + .setPeriod(Period(c.runId, mapCtx.phaseId)) + .setRun(c.run) + try this(ref1) finally mapCtx = saved + } case tp: ClassInfo => mapClassInfo(tp)