Skip to content

Commit b1b1dfd

Browse files
authored
Drop lazy recursive application in approximateParent (#16073)
This plays badly with any code that inspects bounds deeply when creating constraints since the LazyRefs create new type variables at unexpected times. Instead, create the type variables first with empty bounds of the right kind and then add the bounds to the constraint using subtype tests.
2 parents c3ba2f4 + 28c0e79 commit b1b1dfd

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

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

+4-9
Original file line numberDiff line numberDiff line change
@@ -770,20 +770,15 @@ object TypeOps:
770770
tref
771771

772772
case tp: TypeRef if !tp.symbol.isClass =>
773-
def lo = LazyRef.of(apply(tp.underlying.loBound))
774-
def hi = LazyRef.of(apply(tp.underlying.hiBound))
775773
val lookup = boundTypeParams.lookup(tp)
776774
if lookup != null then lookup
777775
else
778-
val tv = newTypeVar(TypeBounds(lo, hi))
776+
val TypeBounds(lo, hi) = tp.underlying.bounds
777+
val tv = newTypeVar(TypeBounds(defn.NothingType, hi.topType))
779778
boundTypeParams(tp) = tv
780-
// Force lazy ref eagerly using current context
781-
// Otherwise, the lazy ref will be forced with a unknown context,
782-
// which causes a problem in tests/patmat/i3645e.scala
783-
lo.ref
784-
hi.ref
779+
assert(tv <:< apply(hi))
780+
apply(lo) <:< tv // no assert, since bounds might conflict
785781
tv
786-
end if
787782

788783
case tp @ AppliedType(tycon: TypeRef, _) if !tycon.dealias.typeSymbol.isClass && !tp.isMatchAlias =>
789784

0 commit comments

Comments
 (0)