summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.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 /src/compiler/scala/tools/nsc/typechecker/Contexts.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 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index eb29ccf4e1..e278130437 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -330,7 +330,7 @@ trait Contexts { self: Analyzer =>
// if set, errors will not be reporter/thrown
def bufferErrors = reporter.isBuffering
- def reportErrors = !bufferErrors
+ def reportErrors = !(bufferErrors || reporter.isThrowing)
// whether to *report* (which is separate from buffering/throwing) ambiguity errors
def ambiguousErrors = this(AmbiguousErrors)
@@ -1247,6 +1247,7 @@ trait Contexts { self: Analyzer =>
def makeImmediate: ContextReporter = this
def makeBuffering: ContextReporter = this
def isBuffering: Boolean = false
+ def isThrowing: Boolean = false
/** Emit an ambiguous error according to context.ambiguousErrors
*
@@ -1384,6 +1385,7 @@ trait Contexts { self: Analyzer =>
* TODO: get rid of it, use ImmediateReporter and a check for reporter.hasErrors where necessary
*/
private[typechecker] class ThrowingReporter extends ContextReporter {
+ override def isThrowing = true
protected def handleError(pos: Position, msg: String): Unit = throw new TypeError(pos, msg)
}