From 2414bfeda301410fe64f8adddd22a24a15621850 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Mon, 6 Jun 2016 17:44:28 +0200 Subject: [PATCH 1/2] Fix issue with GADT not typechecking without bind in match --- src/dotty/tools/dotc/typer/Typer.scala | 5 ++++- tests/pos/i1307.scala | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i1307.scala diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 4f27912f115d..734f1c660966 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1653,7 +1653,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case SearchSuccess(inferred, _, _) => adapt(inferred, pt) case failure: SearchFailure => - if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree + if ( + pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits] || + tree.tpe.<:<(pt)(ctx.addMode(Mode.GADTflexible)) + ) tree else err.typeMismatch(tree, pt, failure) } } diff --git a/tests/pos/i1307.scala b/tests/pos/i1307.scala new file mode 100644 index 000000000000..1dd922321fcd --- /dev/null +++ b/tests/pos/i1307.scala @@ -0,0 +1,7 @@ +class Term[A] +class Number(val n: Int) extends Term[Int] +object Test { + def f[B](t: Term[B]): B = t match { + case y: Number => y.n + } +} From 2b3c5c60cea83b3add2774bbfa840aa91312cb01 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Tue, 7 Jun 2016 16:05:50 +0200 Subject: [PATCH 2/2] Move GADT check to `typeTyped` --- src/dotty/tools/dotc/typer/Typer.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 734f1c660966..07710d3b19cd 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -448,6 +448,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit return typed(untpd.Apply(untpd.TypedSplice(arg), tree.expr), pt) case _ => } + case tref: TypeRef if tref.symbol.isClass && !ctx.isAfterTyper => + val setBefore = ctx.mode is Mode.GADTflexible + tpt1.tpe.<:<(pt)(ctx.addMode(Mode.GADTflexible)) + if (!setBefore) ctx.retractMode(Mode.GADTflexible) case _ => } ascription(tpt1, isWildcard = true) @@ -1653,10 +1657,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case SearchSuccess(inferred, _, _) => adapt(inferred, pt) case failure: SearchFailure => - if ( - pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits] || - tree.tpe.<:<(pt)(ctx.addMode(Mode.GADTflexible)) - ) tree + if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree else err.typeMismatch(tree, pt, failure) } }