Skip to content

Commit 05ba0ab

Browse files
committed
Be more careful with inserted casts.
See comment on the commit for an explanation.
1 parent d848052 commit 05ba0ab

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
@@ -1725,8 +1725,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
17251725
tree
17261726
}
17271727
else if (tree.tpe <:< pt)
1728-
if (ctx.typeComparer.GADTused) tree.asInstance(pt)
1729-
else tree
1728+
if (ctx.typeComparer.GADTused && pt.isValueType && ctx.settings.Ycheck.value.nonEmpty)
1729+
// Insert an explicit cast, so that -Ycheck in later phases succeeds.
1730+
// I suspect, but am not 100% sure that this might affect inferred types,
1731+
// if the expected type is a supertype of the GADT bound. It would be good to come
1732+
// up with a test case for this. For that reason, to be on the safe side
1733+
// we only insert the cast if there are Ychecks later on.
1734+
tree.asInstance(pt)
1735+
else
1736+
tree
17301737
else if (wtp.isInstanceOf[MethodType]) missingArgs
17311738
else {
17321739
typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt")

0 commit comments

Comments
 (0)