-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show GADT bounds in type mismatch message
The inferred GADT bounds can be non-trivial so it makes sense to display them. This commit also showcases the now-improved GADT support in Dotty (both tests/pos/gadt-eval.scala and tests/neg/gadt-eval.scala used to compile, and both compile in Scala 2).
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
sealed trait Exp[T] | ||
case class Lit(value: Int) extends Exp[Int] | ||
case class Pair[A, B](fst: Exp[A], snd: Exp[B]) extends Exp[(A, B)] | ||
|
||
object Test { | ||
def eval[T](e: Exp[T]): T = e match { | ||
case Lit(x) => | ||
x | ||
case Pair(a, b) => | ||
(eval(a), eval(a)) // error: | ||
// -- [E007] Type Mismatch Error: tests/neg/gadt-eval.scala:10:6 ------------------ | ||
// 10 | (eval(a), eval(a)) | ||
// | ^^^^^^^^^^^^^^^^^^ | ||
// | found: (_$1, _$1) | ||
// | required: T | ||
// | | ||
// | where: T is a type in method eval which is an alias of (_$1, _$2) | ||
} | ||
|
||
def eval2[T](e: Exp[T]): T = e match { | ||
case e: Lit => | ||
e.value | ||
case e: Pair[t1, t2] => | ||
(eval(e.fst), eval(e.fst)) // error: | ||
//-- [E007] Type Mismatch Error: tests/neg/gadt-eval.scala:24:6 ------------------ | ||
//24 | (eval(e.fst), eval(e.fst)) | ||
// | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// | found: (t1, t1) | ||
// | required: T | ||
// | | ||
// | where: T is a type in method eval2 which is an alias of (t1, t2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
sealed trait Exp[T] | ||
case class Lit(value: Int) extends Exp[Int] | ||
case class Pair[A, B](fst: Exp[A], snd: Exp[B]) extends Exp[(A, B)] | ||
|
||
object Test { | ||
def eval[T](e: Exp[T]): T = e match { | ||
case Lit(x) => | ||
x | ||
case Pair(a, b) => | ||
(eval(a), eval(b)) | ||
} | ||
|
||
def eval2[T](e: Exp[T]): T = e match { | ||
case e: Lit => | ||
e.value | ||
case e: Pair[t1, t2] => | ||
(eval(e.fst), eval(e.snd)) | ||
} | ||
} |