Skip to content

Commit b607817

Browse files
committed
Fix Typer to use a normal function as LazyRef parameter
1 parent 28714e9 commit b607817

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
541541
// HKLambdas are hash-consed, need to create an artificial difference by adding
542542
// a LazyRef to a bound.
543543
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
544-
paramInfos = TypeBounds(lo, LazyRef(hi)) :: pinfos1
544+
paramInfos = TypeBounds(lo, LazyRef.of(hi)) :: pinfos1
545545
}
546546
ensureFresh(tl.newLikeThis(tl.paramNames, paramInfos, tl.resultType))
547547
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class TypeApplications(val self: Type) extends AnyVal {
363363
case dealiased: TypeBounds =>
364364
dealiased.derivedTypeBounds(dealiased.lo.appliedTo(args), dealiased.hi.appliedTo(args))
365365
case dealiased: LazyRef =>
366-
LazyRef(dealiased.ref.appliedTo(args))
366+
LazyRef.of(dealiased.ref.appliedTo(args))
367367
case dealiased: WildcardType =>
368368
WildcardType(dealiased.optBounds.orElse(TypeBounds.empty).appliedTo(args).bounds)
369369
case dealiased: TypeRef if dealiased.symbol == defn.NothingClass =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ object TypeOps:
687687
tp // break cycles
688688

689689
case tp: TypeRef if !tp.symbol.isClass =>
690-
def lo = LazyRef(apply(tp.underlying.loBound))
691-
def hi = LazyRef(apply(tp.underlying.hiBound))
690+
def lo = LazyRef.of(apply(tp.underlying.loBound))
691+
def hi = LazyRef.of(apply(tp.underlying.hiBound))
692692
val lookup = boundTypeParams.lookup(tp)
693693
if lookup != null then lookup
694694
else

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ object Types {
28002800
}
28012801
}
28022802

2803-
case class LazyRef(private var refFn: Context ?=> Type) extends UncachedProxyType with ValueType {
2803+
case class LazyRef(private var refFn: Context => Type) extends UncachedProxyType with ValueType {
28042804
private var myRef: Type = null
28052805
private var computed = false
28062806

@@ -2813,7 +2813,7 @@ object Types {
28132813
throw CyclicReference(NoDenotation)
28142814
else
28152815
computed = true
2816-
val result = refFn
2816+
val result = refFn(ctx)
28172817
refFn = null
28182818
if result != null then myRef = result
28192819
else assert(myRef != null) // must have been `update`d
@@ -2835,6 +2835,8 @@ object Types {
28352835
override def equals(other: Any): Boolean = this.eq(other.asInstanceOf[AnyRef])
28362836
override def hashCode: Int = System.identityHashCode(this)
28372837
}
2838+
object LazyRef:
2839+
def of(refFn: Context ?=> Type): LazyRef = LazyRef(refFn(using _))
28382840

28392841
// --- Refined Type and RecType ------------------------------------------------
28402842

@@ -4655,7 +4657,7 @@ object Types {
46554657
RefinedType(selfType, sym.name,
46564658
TypeAlias(
46574659
withMode(Mode.CheckCyclic)(
4658-
LazyRef(force))))
4660+
LazyRef.of(force))))
46594661
cinfo.selfInfo match
46604662
case self: Type =>
46614663
cinfo.derivedClassInfo(
@@ -5254,7 +5256,8 @@ object Types {
52545256
derivedSuperType(tp, this(thistp), this(supertp))
52555257

52565258
case tp: LazyRef =>
5257-
LazyRef { refCtx ?=>
5259+
LazyRef { refCtx =>
5260+
given Context = refCtx
52585261
val ref1 = tp.ref
52595262
if refCtx.runId == mapCtx.runId then this(ref1)
52605263
else // splice in new run into map context

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ object Checking {
301301
catch {
302302
case ex: CyclicReference =>
303303
report.debuglog(i"cycle detected for $tp, $nestedCycleOK, $cycleOK")
304-
if (cycleOK) LazyRef(tp)
304+
if (cycleOK) LazyRef.of(tp)
305305
else if (reportErrors) throw ex
306306
else tp
307307
}

0 commit comments

Comments
 (0)