diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 11 |
1 files changed, 10 insertions, 1 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) } |