@@ -26,6 +26,7 @@ import ErrorReporting._
2626import Checking ._
2727import Inferencing ._
2828import EtaExpansion .etaExpand
29+ import TypeComparer .CompareResult
2930import util .Spans ._
3031import util .common ._
3132import util .{Property , SimpleIdentityMap , SrcPos }
@@ -3282,23 +3283,22 @@ class Typer extends Namer
32823283 |To turn this error into a warning, pass -Xignore-scala2-macros to the compiler""" .stripMargin, tree.srcPos.startPos)
32833284 tree
32843285 }
3285- else if (tree.tpe.widenExpr <:< pt) {
3286- if (ctx.typeComparer.GADTused && pt.isValueType)
3286+ else ctx.typeComparer.testSubType(tree.tpe.widenExpr, pt) match
3287+ case CompareResult .Fail =>
3288+ wtp match
3289+ case wtp : MethodType => missingArgs(wtp)
3290+ case _ =>
3291+ typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
3292+ // typr.println(TypeComparer.explained(tree.tpe <:< pt))
3293+ adaptToSubType(wtp)
3294+ case CompareResult .OKwithGADTUsed if pt.isValueType =>
32873295 // Insert an explicit cast, so that -Ycheck in later phases succeeds.
32883296 // I suspect, but am not 100% sure that this might affect inferred types,
32893297 // if the expected type is a supertype of the GADT bound. It would be good to come
32903298 // up with a test case for this.
32913299 tree.cast(pt)
3292- else
3293- tree
3294- }
3295- else wtp match {
3296- case wtp : MethodType => missingArgs(wtp)
32973300 case _ =>
3298- typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
3299- // typr.println(TypeComparer.explained(tree.tpe <:< pt))
3300- adaptToSubType(wtp)
3301- }
3301+ tree
33023302 }
33033303
33043304 // Follow proxies and approximate type paramrefs by their upper bound
0 commit comments