@@ -2860,7 +2860,7 @@ object TrackingTypeComparer:
2860
2860
case Reduced (tp : Type )
2861
2861
case Disjoint
2862
2862
case Stuck
2863
- case NoInstance (param : Name , bounds : TypeBounds )
2863
+ case NoInstance (fails : List [( Name , TypeBounds )] )
2864
2864
2865
2865
class TrackingTypeComparer (initctx : Context ) extends TypeComparer (initctx) {
2866
2866
import TrackingTypeComparer .*
@@ -2906,25 +2906,25 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2906
2906
def paramInstances (canApprox : Boolean ) = new TypeAccumulator [Array [Type ]]:
2907
2907
def apply (insts : Array [Type ], t : Type ) = t match
2908
2908
case param @ TypeParamRef (b, n) if b eq caseLambda =>
2909
- insts(n) = {
2909
+ insts(n) =
2910
2910
if canApprox then
2911
- approximation(param, fromBelow = variance >= 0 )
2911
+ approximation(param, fromBelow = variance >= 0 ).simplified
2912
2912
else constraint.entry(param) match
2913
2913
case entry : TypeBounds =>
2914
2914
val lo = fullLowerBound(param)
2915
2915
val hi = fullUpperBound(param)
2916
- if isSubType(hi, lo) then lo else TypeBounds (lo, hi)
2916
+ if isSubType(hi, lo) then lo.simplified else Range (lo, hi)
2917
2917
case inst =>
2918
2918
assert(inst.exists, i " param = $param\n constraint = $constraint" )
2919
- inst
2920
- }.simplified
2919
+ inst.simplified
2921
2920
insts
2922
2921
case _ =>
2923
2922
foldOver(insts, t)
2924
2923
2925
- def instantiateParams (inst : Array [Type ]) = new TypeMap {
2924
+ def instantiateParams (insts : Array [Type ]) = new ApproximatingTypeMap {
2925
+ variance = 0
2926
2926
def apply (t : Type ) = t match {
2927
- case t @ TypeParamRef (b, n) if b `eq` caseLambda => inst (n)
2927
+ case t @ TypeParamRef (b, n) if b `eq` caseLambda => insts (n)
2928
2928
case t : LazyRef => apply(t.ref)
2929
2929
case _ => mapOver(t)
2930
2930
}
@@ -2957,11 +2957,15 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2957
2957
caseLambda match
2958
2958
case caseLambda : HKTypeLambda =>
2959
2959
val instances = paramInstances(canApprox)(new Array (caseLambda.paramNames.length), pat)
2960
- instances.indices.find(instances(_).isInstanceOf [TypeBounds ]) match
2961
- case Some (i) if ! canApprox =>
2962
- MatchResult .NoInstance (caseLambda.paramNames(i), instances(i).bounds)
2963
- case _ =>
2964
- MatchResult .Reduced (instantiateParams(instances)(body).simplified)
2960
+ instantiateParams(instances)(body) match
2961
+ case Range (lo, hi) =>
2962
+ MatchResult .NoInstance {
2963
+ caseLambda.paramNames.zip(instances).collect {
2964
+ case (name, Range (lo, hi)) => (name, TypeBounds (lo, hi))
2965
+ }
2966
+ }
2967
+ case redux =>
2968
+ MatchResult .Reduced (redux.simplified)
2965
2969
case _ =>
2966
2970
MatchResult .Reduced (body)
2967
2971
@@ -2985,8 +2989,8 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
2985
2989
case MatchResult .Stuck =>
2986
2990
MatchTypeTrace .stuck(scrut, cas, remaining1)
2987
2991
NoType
2988
- case MatchResult .NoInstance (pname, bounds ) =>
2989
- MatchTypeTrace .noInstance(scrut, cas, pname, bounds )
2992
+ case MatchResult .NoInstance (fails ) =>
2993
+ MatchTypeTrace .noInstance(scrut, cas, fails )
2990
2994
NoType
2991
2995
case MatchResult .Reduced (tp) =>
2992
2996
tp
0 commit comments