@@ -2856,7 +2856,7 @@ object TrackingTypeComparer:
28562856 case Reduced (tp : Type )
28572857 case Disjoint
28582858 case Stuck
2859- case NoInstance (param : Name , bounds : TypeBounds )
2859+ case NoInstance (fails : List [( Name , TypeBounds )] )
28602860
28612861class TrackingTypeComparer (initctx : Context ) extends TypeComparer (initctx) {
28622862 import TrackingTypeComparer .*
@@ -2902,25 +2902,25 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
29022902 def paramInstances (canApprox : Boolean ) = new TypeAccumulator [Array [Type ]]:
29032903 def apply (insts : Array [Type ], t : Type ) = t match
29042904 case param @ TypeParamRef (b, n) if b eq caseLambda =>
2905- insts(n) = {
2905+ insts(n) =
29062906 if canApprox then
2907- approximation(param, fromBelow = variance >= 0 )
2907+ approximation(param, fromBelow = variance >= 0 ).simplified
29082908 else constraint.entry(param) match
29092909 case entry : TypeBounds =>
29102910 val lo = fullLowerBound(param)
29112911 val hi = fullUpperBound(param)
2912- if isSubType(hi, lo) then lo else TypeBounds (lo, hi)
2912+ if isSubType(hi, lo) then lo.simplified else Range (lo, hi)
29132913 case inst =>
29142914 assert(inst.exists, i " param = $param\n constraint = $constraint" )
2915- inst
2916- }.simplified
2915+ inst.simplified
29172916 insts
29182917 case _ =>
29192918 foldOver(insts, t)
29202919
2921- def instantiateParams (inst : Array [Type ]) = new TypeMap {
2920+ def instantiateParams (insts : Array [Type ]) = new ApproximatingTypeMap {
2921+ variance = 0
29222922 def apply (t : Type ) = t match {
2923- case t @ TypeParamRef (b, n) if b `eq` caseLambda => inst (n)
2923+ case t @ TypeParamRef (b, n) if b `eq` caseLambda => insts (n)
29242924 case t : LazyRef => apply(t.ref)
29252925 case _ => mapOver(t)
29262926 }
@@ -2953,11 +2953,15 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
29532953 caseLambda match
29542954 case caseLambda : HKTypeLambda =>
29552955 val instances = paramInstances(canApprox)(new Array (caseLambda.paramNames.length), pat)
2956- instances.indices.find(instances(_).isInstanceOf [TypeBounds ]) match
2957- case Some (i) if ! canApprox =>
2958- MatchResult .NoInstance (caseLambda.paramNames(i), instances(i).bounds)
2959- case _ =>
2960- MatchResult .Reduced (instantiateParams(instances)(body).simplified)
2956+ instantiateParams(instances)(body) match
2957+ case Range (lo, hi) =>
2958+ MatchResult .NoInstance {
2959+ caseLambda.paramNames.zip(instances).collect {
2960+ case (name, Range (lo, hi)) => (name, TypeBounds (lo, hi))
2961+ }
2962+ }
2963+ case redux =>
2964+ MatchResult .Reduced (redux.simplified)
29612965 case _ =>
29622966 MatchResult .Reduced (body)
29632967
@@ -2981,8 +2985,8 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
29812985 case MatchResult .Stuck =>
29822986 MatchTypeTrace .stuck(scrut, cas, remaining1)
29832987 NoType
2984- case MatchResult .NoInstance (pname, bounds ) =>
2985- MatchTypeTrace .noInstance(scrut, cas, pname, bounds )
2988+ case MatchResult .NoInstance (fails ) =>
2989+ MatchTypeTrace .noInstance(scrut, cas, fails )
29862990 NoType
29872991 case MatchResult .Reduced (tp) =>
29882992 tp
0 commit comments