@@ -96,17 +96,17 @@ object TypeTestsCasts {
9696 val tvars = constrained(typeLambda, untpd.EmptyTree , alwaysAddTypeVars = true )._2.map(_.tpe)
9797 val P1 = tycon.appliedTo(tvars)
9898
99- debug.println(" P : " + P )
100- debug.println(" P1 : " + P1 )
101- debug.println(" X : " + X )
99+ debug.println(" P : " + P .show )
100+ debug.println(" P1 : " + P1 .show )
101+ debug.println(" X : " + X .show )
102102
103103 P1 <:< X // constraint P1
104104
105105 // use fromScala2x to avoid generating pattern bound symbols
106106 maximizeType(P1 , span, fromScala2x = true )
107107
108108 val res = P1 <:< P
109- debug.println(" P1 : " + P1 )
109+ debug.println(" P1 : " + P1 .show )
110110 debug.println(" P1 <:< P = " + res)
111111
112112 res
@@ -122,9 +122,19 @@ object TypeTestsCasts {
122122 case _ => recur(defn.AnyType , tpT)
123123 }
124124 case tpe : AppliedType =>
125- // first try withou striping type parameters for performance
126- isClassDetermined(X , tpe)(ctx.fresh.setNewTyperState()) ||
127- isClassDetermined(stripTypeParam(X ), tpe)(ctx.fresh.setNewTyperState())
125+ X .widen match {
126+ case OrType (tp1, tp2) =>
127+ // This case is required to retrofit type inference,
128+ // which cut constraints in the following two cases:
129+ // - T1 <:< T2 | T3
130+ // - T1 & T2 <:< T3
131+ // See TypeComparer#either
132+ recur(tp1, P ) && recur(tp2, P )
133+ case _ =>
134+ // first try withou striping type parameters for performance
135+ isClassDetermined(X , tpe)(ctx.fresh.setNewTyperState()) ||
136+ isClassDetermined(stripTypeParam(X ), tpe)(ctx.fresh.setNewTyperState())
137+ }
128138 case AndType (tp1, tp2) => recur(X , tp1) && recur(X , tp2)
129139 case OrType (tp1, tp2) => recur(X , tp1) && recur(X , tp2)
130140 case AnnotatedType (t, _) => recur(X , t)
0 commit comments