Skip to content

Commit

Permalink
Drop lazy recursive application in approximateParent (scala#16073)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky authored Sep 20, 2022
2 parents c3ba2f4 + 28c0e79 commit b1b1dfd
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -770,20 +770,15 @@ object TypeOps:
tref

case tp: TypeRef if !tp.symbol.isClass =>
def lo = LazyRef.of(apply(tp.underlying.loBound))
def hi = LazyRef.of(apply(tp.underlying.hiBound))
val lookup = boundTypeParams.lookup(tp)
if lookup != null then lookup
else
val tv = newTypeVar(TypeBounds(lo, hi))
val TypeBounds(lo, hi) = tp.underlying.bounds
val tv = newTypeVar(TypeBounds(defn.NothingType, hi.topType))
boundTypeParams(tp) = tv
// Force lazy ref eagerly using current context
// Otherwise, the lazy ref will be forced with a unknown context,
// which causes a problem in tests/patmat/i3645e.scala
lo.ref
hi.ref
assert(tv <:< apply(hi))
apply(lo) <:< tv // no assert, since bounds might conflict
tv
end if

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

Expand Down

0 comments on commit b1b1dfd

Please sign in to comment.