diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-04 08:56:39 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-07-04 08:56:39 -0700 |
commit | e9a696ce610c141a6a21f4201229ed52c1ccebc3 (patch) | |
tree | f25b031ee7a9838ddcccc259dfb6ad408abbb4e8 | |
parent | cb066cc6af2e836d66593d2fec56bc2c6a786d1a (diff) | |
parent | e6796eb516968c13957fc99954ec0a9862bb0111 (diff) | |
download | scala-e9a696ce610c141a6a21f4201229ed52c1ccebc3.tar.gz scala-e9a696ce610c141a6a21f4201229ed52c1ccebc3.tar.bz2 scala-e9a696ce610c141a6a21f4201229ed52c1ccebc3.zip |
Merge pull request #814 from hubertp/issue/5969
Closes SI-5969.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 11 | ||||
-rw-r--r-- | test/files/neg/t5969.check | 7 | ||||
-rw-r--r-- | test/files/neg/t5969.scala | 11 | ||||
-rw-r--r-- | test/files/neg/t649.check | 2 |
4 files changed, 29 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index e99c31374e..960c210649 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1614,6 +1614,13 @@ trait Infer { val saved = context.state var fallback = false context.setBufferErrors() + // We cache the current buffer because it is impossible to + // distinguish errors that occurred before entering tryTwice + // and our first attempt in 'withImplicitsDisabled'. If the + // first attempt fails we try with implicits on *and* clean + // buffer but that would also flush any pre-tryTwice valid + // errors, hence some manual buffer tweaking is necessary. + val errorsToRestore = context.flushAndReturnBuffer() try { context.withImplicitsDisabled(infer(false)) if (context.hasErrors) { @@ -1627,8 +1634,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 |