diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 20b5dec2f966..1b44c965b0f7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3136,15 +3136,15 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { case param @ TypeParamRef(b, n) if b eq caseLambda => insts(n) = if canApprox then - approximation(param, fromBelow = variance >= 0, Int.MaxValue).simplified + approximation(param, fromBelow = variance >= 0, Int.MaxValue).normalized else constraint.entry(param) match case entry: TypeBounds => val lo = fullLowerBound(param) val hi = fullUpperBound(param) - if !poisoned(param) && isSubType(hi, lo) then lo.simplified else Range(lo, hi) + if !poisoned(param) && isSubType(hi, lo) then lo.normalized else Range(lo, hi) case inst => assert(inst.exists, i"param = $param\nconstraint = $constraint") - if !poisoned(param) then inst.simplified else Range(inst, inst) + if !poisoned(param) then inst.normalized else Range(inst, inst) insts case _ => foldOver(insts, t) @@ -3166,6 +3166,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { } } + def normalizeHard(tp: Type): Type = tp.tryNormalize.orElse(tp match { + case tp: AppliedType => tp.map(normalizeHard) + case _ => tp + }) + /** Match a single case. */ def matchCase(cas: Type): MatchResult = trace(i"$scrut match ${MatchTypeTrace.caseText(cas)}", matchTypes, show = true) { val cas1 = cas match { @@ -3229,7 +3234,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { MatchTypeTrace.noInstance(scrut, cas, fails) NoType case MatchResult.Reduced(tp) => - tp.simplified + normalizeHard(tp) case Nil => val casesText = MatchTypeTrace.noMatchesText(scrut, cases) ErrorType(reporting.MatchTypeNoCases(casesText)) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 6809e4b9083c..c27bb7e9c27b 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -184,7 +184,7 @@ object TypeOps: else tp.derivedAnnotatedType(parent1, annot) case _: MatchType => val normed = tp.tryNormalize - if (normed.exists) normed else mapOver + if (normed.exists) simplify(normed, theMap) else mapOver case tp: MethodicType => // See documentation of `Types#simplified` val addTypeVars = new TypeMap with IdempotentCaptRefMap: diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 4e61510f0062..7555ba41e58d 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -359,7 +359,7 @@ object Types { * (since these are relevant for inference or resolution) but never consider prefixes * (since these often do not constrain the search space anyway). */ - def unusableForInference(using Context): Boolean = try widenDealias match + def unusableForInference(using Context): Boolean = widenDealias match case AppliedType(tycon, args) => tycon.unusableForInference || args.exists(_.unusableForInference) case RefinedType(parent, _, rinfo) => parent.unusableForInference || rinfo.unusableForInference case TypeBounds(lo, hi) => lo.unusableForInference || hi.unusableForInference @@ -369,7 +369,6 @@ object Types { case CapturingType(parent, refs) => parent.unusableForInference || refs.elems.exists(_.unusableForInference) case _: ErrorType => true case _ => false - catch case ex: Throwable => handleRecursive("unusableForInference", show, ex) /** Does the type carry an annotation that is an instance of `cls`? */ @tailrec final def hasAnnotation(cls: ClassSymbol)(using Context): Boolean = stripTypeVar match { diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index e89447c5ddb1..0e1c41ceef74 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -198,7 +198,7 @@ object Inferencing { case tp => foldOver(x, tp) } catch case ex: Throwable => - handleRecursive("check fully defined", tp.showSummary(20), ex) + handleRecursive("check fully defined", tp.show, ex) } def process(tp: Type): Boolean = diff --git a/tests/neg-custom-args/isInstanceOf/i17435.scala b/tests/neg-custom-args/isInstanceOf/i17435.scala index 3fb624e57f7e..e32149db3137 100644 --- a/tests/neg-custom-args/isInstanceOf/i17435.scala +++ b/tests/neg-custom-args/isInstanceOf/i17435.scala @@ -14,10 +14,10 @@ object Test: type JsonArray = mutable.Buffer[Json] def encode(x: Json): Int = x match - case str: String => 1 // error - case b: Boolean => 2 // error - case i: Int => 3 // error - case d: Double => 4 // error + case str: String => 1 + case b: Boolean => 2 + case i: Int => 3 + case d: Double => 4 case arr: JsonArray => 5 // error case obj: JsonObject => 6 // error case _ => 7 diff --git a/tests/neg/i15158.scala b/tests/neg/i15158.scala index 65f785c1f975..6c4f0f1f290e 100644 --- a/tests/neg/i15158.scala +++ b/tests/neg/i15158.scala @@ -38,6 +38,6 @@ class Spec { JsonPrimitive ] - val arr = new mutable.ArrayBuffer[Json](8) // error + val arr = new mutable.ArrayBuffer[Json](8) } }