Skip to content

Fix #1737: Enable GADT checking for objects #1740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ =>
}
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i1737.scala
Original file line number Diff line number Diff line change
@@ -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"
}
}