Skip to content

Commit 2414bfe

Browse files
committed
Fix issue with GADT not typechecking without bind in match
1 parent 04b0e85 commit 2414bfe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16531653
case SearchSuccess(inferred, _, _) =>
16541654
adapt(inferred, pt)
16551655
case failure: SearchFailure =>
1656-
if (pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits]) tree
1656+
if (
1657+
pt.isInstanceOf[ProtoType] && !failure.isInstanceOf[AmbiguousImplicits] ||
1658+
tree.tpe.<:<(pt)(ctx.addMode(Mode.GADTflexible))
1659+
) tree
16571660
else err.typeMismatch(tree, pt, failure)
16581661
}
16591662
}

tests/pos/i1307.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Term[A]
2+
class Number(val n: Int) extends Term[Int]
3+
object Test {
4+
def f[B](t: Term[B]): B = t match {
5+
case y: Number => y.n
6+
}
7+
}

0 commit comments

Comments
 (0)