Skip to content

Commit 624d6ad

Browse files
committed
Be more careful with inserted casts.
See comment on the commit for an explanation.
1 parent f6f96af commit 624d6ad

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,8 +1689,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16891689
tree
16901690
}
16911691
else if (tree.tpe <:< pt)
1692-
if (ctx.typeComparer.GADTused) tree.asInstance(pt)
1693-
else tree
1692+
if (ctx.typeComparer.GADTused && pt.isValueType && ctx.settings.Ycheck.value.nonEmpty)
1693+
// Insert an explicit cast, so that -Ycheck in later phases succeeds.
1694+
// I suspect, but am not 100% sure that this might affect inferred types,
1695+
// if the expected type is a supertype of the GADT bound. It would be good to come
1696+
// up with a test case for this. For that reason, to be on the safe side
1697+
// we only insert the cast if there are Ychecks later on.
1698+
tree.asInstance(pt)
1699+
else
1700+
tree
16941701
else if (wtp.isInstanceOf[MethodType]) missingArgs
16951702
else {
16961703
typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt")

0 commit comments

Comments
 (0)