Skip to content

Commit 3588832

Browse files
authored
Merge pull request #1740 from dotty-staging/fix-#1737
Fix #1737: Enable GADT checking for objects
2 parents 3599c24 + a911a70 commit 3588832

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18301830
ctx.typeComparer.GADTused = false
18311831
if (ctx.mode is Mode.Pattern) {
18321832
tree match {
1833-
case _: RefTree | _: Literal if !isVarPattern(tree) =>
1833+
case _: RefTree | _: Literal
1834+
if !isVarPattern(tree) &&
1835+
!(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) =>
18341836
checkCanEqual(pt, wtp, tree.pos)(ctx.retractMode(Mode.Pattern))
18351837
case _ =>
18361838
}

tests/pos/i1737.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
sealed trait Foo[A]
3+
case object FooI extends Foo[Int]
4+
case class FooS(b: Boolean) extends Foo[String]
5+
6+
def algFoo[A](foo: Foo[A]): A =
7+
foo match {
8+
case FooI => 42
9+
case FooS(b) => "foo"
10+
}
11+
}

0 commit comments

Comments
 (0)