diff options
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Typer.scala | 4 | ||||
-rw-r--r-- | tests/pos/i1737.scala | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9f5a942d6..ccc74cfff 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1830,7 +1830,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit ctx.typeComparer.GADTused = false if (ctx.mode is Mode.Pattern) { tree match { - case _: RefTree | _: Literal if !isVarPattern(tree) => + case _: RefTree | _: Literal + if !isVarPattern(tree) && + !(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) => checkCanEqual(pt, wtp, tree.pos)(ctx.retractMode(Mode.Pattern)) case _ => } diff --git a/tests/pos/i1737.scala b/tests/pos/i1737.scala new file mode 100644 index 000000000..e7b428717 --- /dev/null +++ b/tests/pos/i1737.scala @@ -0,0 +1,11 @@ +object Test { + sealed trait Foo[A] + case object FooI extends Foo[Int] + case class FooS(b: Boolean) extends Foo[String] + + def algFoo[A](foo: Foo[A]): A = + foo match { + case FooI => 42 + case FooS(b) => "foo" + } +} |