From 05ba0abd71ef6e0aa281d32c0723bca515421697 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 20:08:58 +0200 Subject: Be more careful with inserted casts. See comment on the commit for an explanation. --- src/dotty/tools/dotc/typer/Typer.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Typer.scala') 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") -- cgit v1.2.3