summaryrefslogtreecommitdiff
path: root/test/files/pos/t8962.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-11-06 13:12:19 +1000
committerJason Zaugg <jzaugg@gmail.com>2014-11-06 14:28:29 +1000
commitd6d8c06e02fa1e93e5dd37eeb08b2c1bb3805dd8 (patch)
tree7822cc48706c201d5b0cdb23d6e583534bb7847c /test/files/pos/t8962.scala
parentcd50464cd019bc6a489a72b98293c30b91352bab (diff)
downloadscala-d6d8c06e02fa1e93e5dd37eeb08b2c1bb3805dd8.tar.gz
scala-d6d8c06e02fa1e93e5dd37eeb08b2c1bb3805dd8.tar.bz2
scala-d6d8c06e02fa1e93e5dd37eeb08b2c1bb3805dd8.zip
SI-8962 Fix regression with skolems in pattern translation
During the refactoring of error reporting in 258d95c7b15, the result of `Context#reportError` was changed once we had switched to using a `ThrowingReporter`, which is still the case in post typer phase typechecking This was enough to provoke a type error in the enclosed test. Here's a diff of the typer log: % scalac-hash 258d95~1 -Ytyper-debug sandbox/test.scala 2>&1 | tee sandbox/good.log % scalac-hash 258d95 -Ytyper-debug sandbox/test.scala 2>&1 | tee sandbox/bad.log % diff -U100 sandbox/{good,bad}.log | gist --filename=SI-8962-typer-log.diff https://gist.github.com/retronym/3ccbe7e0791447d272a6 The test `Context#reportError` happens to be used when deciding whether the type checker should be lenient when it hits a type error. In lenient mode (see `adaptMismatchedSkolems`), it `adapt` retries with after slackening the expected type by replacing GADT and existential skolems with wildcard types. This is to accomodate known type-incorrect trees generated by the pattern matcher. This commit restores the old semantics of `reportError`, which means it is `false` when a `ThrowingReporter` is being used. For those still reading, here's some more details. The trees of the `run2` example from the enclosed test. Notice that after typechecking, `expr` has a type containing GADT skolems. The pattern matcher assumes that calling the case field accessor `expr` on the temporary val `x2 : Let[A with A]` containing the scrutinee will result in a compatible expression, however this it does not. Perhaps the pattern matcher should generate casts, rather than relying on the typer to turn a blind eye. ``` [[syntax trees at end of typer]] // t8962b.scala ... def run2[A](nc: Outer2[A,A]): Outer2[Inner2[A],A] = nc match { case (expr: Outer2[Inner2[?A2 with ?A1],?A2 with ?A1])Let2[A with A]((expr @ _{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}){Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}){Let2[A with A]} => (expr{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}: Outer2[Inner2[A],A]){Outer2[Inner2[A],A]} }{Outer2[Inner2[A],A]} [[syntax trees at end of patmat]] // t8962b.scala def run2[A](nc: Outer2[A,A]): Outer2[Inner2[A],A] = { case <synthetic> val x1: Outer2[A,A] = nc{Outer2[A,A]}; case5(){ if (x1.isInstanceOf[Let2[A with A]]) { <synthetic> val x2: Let2[A with A] = (x1.asInstanceOf[Let2[A with A]]: Let2[A with A]){Let2[A with A]}; { val expr: Outer2[Inner2[?A2 with ?A1],?A2 with ?A1] = x2.expr{<null>}; matchEnd4{<null>}((expr{Outer2[Inner2[?A2 with ?A1],?A2 with ?A1]}: Outer2[Inner2[A],A]){Outer2[Inner2[A],A]}){<null>} ... ```
Diffstat (limited to 'test/files/pos/t8962.scala')
-rw-r--r--test/files/pos/t8962.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/pos/t8962.scala b/test/files/pos/t8962.scala
new file mode 100644
index 0000000000..4331c154ba
--- /dev/null
+++ b/test/files/pos/t8962.scala
@@ -0,0 +1,31 @@
+package test.nestedcov
+
+sealed abstract class Outer[+A]
+case class Let[+A](expr: Outer[Inner[A]]) extends Outer[A]
+
+sealed abstract class Inner[+A]
+
+sealed abstract class Outer2[+A, +B]
+case class Let2[+A](expr: Outer2[Inner2[A], A]) extends Outer2[A, A]
+
+sealed abstract class Inner2[+A]
+
+sealed abstract class Outer3[+A, +B]
+case class Let3[+A](expr: Outer3[A, A]) extends Outer3[A, A]
+
+object NestedCov {
+ def run[A](nc: Outer[A]) = nc match {
+ case Let(expr) =>
+ expr : Outer[Inner[A]]
+ }
+
+ def run2[A](nc: Outer2[A, A]) = nc match {
+ case Let2(expr) =>
+ expr : Outer2[Inner2[A], A]
+ }
+
+ def run3[A](nc: Outer3[A, A]) = nc match {
+ case Let3(expr) =>
+ expr : Outer3[A, A]
+ }
+}