@@ -26,6 +26,7 @@ import ErrorReporting._
26
26
import Checking ._
27
27
import Inferencing ._
28
28
import EtaExpansion .etaExpand
29
+ import TypeComparer .CompareResult
29
30
import util .Spans ._
30
31
import util .common ._
31
32
import util .Property
@@ -3248,23 +3249,22 @@ class Typer extends Namer
3248
3249
|To turn this error into a warning, pass -Xignore-scala2-macros to the compiler""" .stripMargin, tree.sourcePos.startPos)
3249
3250
tree
3250
3251
}
3251
- else if (tree.tpe.widenExpr <:< pt) {
3252
- if (ctx.typeComparer.GADTused && pt.isValueType)
3252
+ else ctx.typeComparer.testSubType(tree.tpe.widenExpr, pt) match
3253
+ case CompareResult .Fail =>
3254
+ wtp match
3255
+ case wtp : MethodType => missingArgs(wtp)
3256
+ case _ =>
3257
+ typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
3258
+ // typr.println(TypeComparer.explained(tree.tpe <:< pt))
3259
+ adaptToSubType(wtp)
3260
+ case CompareResult .OKwithGADTUsed if pt.isValueType =>
3253
3261
// Insert an explicit cast, so that -Ycheck in later phases succeeds.
3254
3262
// I suspect, but am not 100% sure that this might affect inferred types,
3255
3263
// if the expected type is a supertype of the GADT bound. It would be good to come
3256
3264
// up with a test case for this.
3257
3265
tree.cast(pt)
3258
- else
3259
- tree
3260
- }
3261
- else wtp match {
3262
- case wtp : MethodType => missingArgs(wtp)
3263
3266
case _ =>
3264
- typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
3265
- // typr.println(TypeComparer.explained(tree.tpe <:< pt))
3266
- adaptToSubType(wtp)
3267
- }
3267
+ tree
3268
3268
}
3269
3269
3270
3270
// Follow proxies and approximate type paramrefs by their upper bound
0 commit comments