From 28c0e79a2da5ac86ca1278e85855ffe3c4713382 Mon Sep 17 00:00:00 2001 From: odersky Date: Mon, 19 Sep 2022 18:33:45 +0200 Subject: [PATCH] Drop lazy recursive application in approximateParent 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 an empty constraint of the right kind and then add the bounds to the constraint using subtype tests. --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 0c58cab0347f..332129e72850 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -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 =>