summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert.plociniczak@gmail.com>2012-06-27 15:43:44 +0200
committerHubert Plociniczak <hubert.plociniczak@gmail.com>2012-07-02 14:44:43 +0200
commit12b72485d873534bcce0b0564c99d89d6b1aa964 (patch)
tree35fded7d09ae48e053f580d6dff11323cd92f26e
parent5a7bbfe035ecb64acd57fc66ea0d874ad02c31ff (diff)
downloadscala-12b72485d873534bcce0b0564c99d89d6b1aa964.tar.gz
scala-12b72485d873534bcce0b0564c99d89d6b1aa964.tar.bz2
scala-12b72485d873534bcce0b0564c99d89d6b1aa964.zip
Closes SI-5969.
Assumption that we enter tryTwice when inferring the right alternative with an empty buffer is wrong. In this particular bug it manifested itself on if/then/else which share the same context and 'else' branch was simply flushing the buffer with an error from the 'then' branch.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala7
-rw-r--r--test/files/neg/t5969.check7
-rw-r--r--test/files/neg/t5969.scala11
-rw-r--r--test/files/neg/t649.check2
4 files changed, 25 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 688dcd91ac..e1aabb5469 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1612,6 +1612,9 @@ trait Infer {
val saved = context.state
var fallback = false
context.setBufferErrors()
+ // Need to test first attempt with an empty buffer.
+ // Otherwise, any previous errors will get lost.
+ val errorsToRestore = context.flushAndReturnBuffer()
try {
context.withImplicitsDisabled(infer(false))
if (context.hasErrors) {
@@ -1625,8 +1628,10 @@ trait Infer {
case ex: TypeError => // recoverable cyclic references
context.restoreState(saved)
if (!fallback) infer(true) else ()
+ } finally {
+ context.restoreState(saved)
+ context.updateBuffer(errorsToRestore)
}
- context.restoreState(saved)
}
else infer(true)
}
diff --git a/test/files/neg/t5969.check b/test/files/neg/t5969.check
new file mode 100644
index 0000000000..9d8ac9a3a5
--- /dev/null
+++ b/test/files/neg/t5969.check
@@ -0,0 +1,7 @@
+t5969.scala:9: error: overloaded method value g with alternatives:
+ (x: C2)String <and>
+ (x: C1)String
+ cannot be applied to (String)
+ if (false) List(g(x)) else List[C1]() map g
+ ^
+one error found
diff --git a/test/files/neg/t5969.scala b/test/files/neg/t5969.scala
new file mode 100644
index 0000000000..62f87fd7ab
--- /dev/null
+++ b/test/files/neg/t5969.scala
@@ -0,0 +1,11 @@
+class C1
+class C2
+class A {
+ def f(x: Any) = x
+ def g(x: C1): String = "A"
+ def g(x: C2): String = "B"
+
+ def crash() = f(List[String]() flatMap { x =>
+ if (false) List(g(x)) else List[C1]() map g
+ })
+}
diff --git a/test/files/neg/t649.check b/test/files/neg/t649.check
index a6670886b5..5a270d4751 100644
--- a/test/files/neg/t649.check
+++ b/test/files/neg/t649.check
@@ -1,4 +1,4 @@
t649.scala:3: error: overloaded method foo needs result type
def foo[A] = foo[A]
- ^
+ ^
one error found