diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index e5711cdb8256..0e0b54f0ba4b 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -244,44 +244,36 @@ object TypeOps: def mergeRefinedOrApplied(tp1: Type, tp2: Type): Type = { def fail = throw new AssertionError(i"Failure to join alternatives $tp1 and $tp2") - def fallback = tp2 match + + tp2 match case AndType(tp21, tp22) => - mergeRefinedOrApplied(tp1, tp21) & mergeRefinedOrApplied(tp1, tp22) + return mergeRefinedOrApplied(tp1, tp21) & mergeRefinedOrApplied(tp1, tp22) case _ => - fail - tp1 match { + + if tp1 eq tp2 then tp1 + else tp1 match case tp1 @ RefinedType(parent1, name1, rinfo1) => - tp2 match { + tp2 match case RefinedType(parent2, `name1`, rinfo2) => tp1.derivedRefinedType( mergeRefinedOrApplied(parent1, parent2), name1, rinfo1 | rinfo2) - case _ => fallback - } + case _ => fail case tp1 @ AppliedType(tycon1, args1) => - tp2 match { + tp2 match case AppliedType(tycon2, args2) => tp1.derivedAppliedType( mergeRefinedOrApplied(tycon1, tycon2), TypeComparer.lubArgs(args1, args2, tycon1.typeParams)) - case _ => fallback - } + case _ => fail case tp1 @ TypeRef(pre1, _) => - tp2 match { + tp2 match case tp2 @ TypeRef(pre2, _) if tp1.name eq tp2.name => tp1.derivedSelect(pre1 | pre2) - case _ => fallback - } - case tp1: TypeParamRef => - tp2 match { - case tp2: TypeParamRef - if (tp1.binder eq tp2.binder) && (tp1.paramNum == tp2.paramNum) => - tp1 - case _ => fallback - } + case _ => fail case AndType(tp11, tp12) => mergeRefinedOrApplied(tp11, tp2) & mergeRefinedOrApplied(tp12, tp2) + case tp1: TypeParamRef if tp1 == tp2 => tp1 case _ => fail - } } def approximateOr(tp1: Type, tp2: Type): Type = {