aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-08-22 20:08:58 +0200
committerMartin Odersky <odersky@gmail.com>2016-08-26 11:13:16 +0200
commit05ba0abd71ef6e0aa281d32c0723bca515421697 (patch)
treed836193f4d1e55bf68851c1436136611b905284b /src/dotty/tools/dotc/typer/Typer.scala
parentd84805299a42cb8d2c756aff5a117af24dbeaaf4 (diff)
downloaddotty-05ba0abd71ef6e0aa281d32c0723bca515421697.tar.gz
dotty-05ba0abd71ef6e0aa281d32c0723bca515421697.tar.bz2
dotty-05ba0abd71ef6e0aa281d32c0723bca515421697.zip
Be more careful with inserted casts.
See comment on the commit for an explanation.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 39d9d267e..10c69099d 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1725,8 +1725,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tree
}
else if (tree.tpe <:< pt)
- if (ctx.typeComparer.GADTused) tree.asInstance(pt)
- else tree
+ if (ctx.typeComparer.GADTused && pt.isValueType && ctx.settings.Ycheck.value.nonEmpty)
+ // Insert an explicit cast, so that -Ycheck in later phases succeeds.
+ // I suspect, but am not 100% sure that this might affect inferred types,
+ // if the expected type is a supertype of the GADT bound. It would be good to come
+ // up with a test case for this. For that reason, to be on the safe side
+ // we only insert the cast if there are Ychecks later on.
+ tree.asInstance(pt)
+ else
+ tree
else if (wtp.isInstanceOf[MethodType]) missingArgs
else {
typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt")