From 386dddde5361e5c2b9876dbb8855a0f1a81ca95b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 10 Aug 2011 07:03:13 +0000 Subject: Turned up the defense against compiler exceptio... Turned up the defense against compiler exceptions in the repl. And gave in and disabled an assertion I should have disabled two years ago. Closes SI-4874, no review. --- src/compiler/scala/reflect/internal/Symbols.scala | 8 +++-- .../tools/nsc/interpreter/JLineCompletion.scala | 34 +++++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 4789d69c69..632b7194f8 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -615,11 +615,13 @@ trait Symbols extends api.Symbols { self: SymbolTable => rawowner = owner } private[Symbols] def flattenName(): Name = { - // TODO: this assertion causes me a lot of trouble in the interpeter in situations + // This assertion caused me no end of trouble in the interpeter in situations // where everything proceeds smoothly if there's no assert. I don't think calling "name" // on a symbol is the right place to throw fatal exceptions if things don't look right. - // It really hampers exploration. - assert(rawowner.isClass, "fatal: %s has non-class owner %s after flatten.".format(rawname + idString, rawowner)) + // It really hampers exploration. Finally I gave up and disabled it, and tickets like + // SI-4874 instantly start working. + // assert(rawowner.isClass, "fatal: %s has non-class owner %s after flatten.".format(rawname + idString, rawowner)) + nme.flattenedName(rawowner.name, rawname) } diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala index 8b387823ff..9c5299b633 100644 --- a/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala +++ b/src/compiler/scala/tools/nsc/interpreter/JLineCompletion.scala @@ -359,18 +359,30 @@ class JLineCompletion(val intp: IMain) extends Completion with CompletionOutput if (!looksLikePath(buf)) None else tryCompletion(mkUndelimited, FileCompletion completionsFor _.buffer) - /** This is the kickoff point for all manner of theoretically possible compiler - * unhappiness - fault may be here or elsewhere, but we don't want to crash the - * repl regardless. Hopefully catching Exception is enough, but because the - * compiler still throws some Errors it may not be. + def tryAll = ( + lastResultCompletion + orElse regularCompletion + orElse fileCompletion + getOrElse Candidates(cursor, Nil) + ) + + /** + * This is the kickoff point for all manner of theoretically + * possible compiler unhappiness. The fault may be here or + * elsewhere, but we don't want to crash the repl regardless. + * The compiler makes it impossible to avoid catching Throwable + * with its unfortunate tendency to throw java.lang.Errors and + * AssertionErrors as the hats drop. We take two swings at it + * because there are some spots which like to throw an assertion + * once, then work after that. Yeah, what can I say. */ - try { - (lastResultCompletion orElse regularCompletion orElse fileCompletion) getOrElse Candidates(cursor, Nil) - } - catch { - case ex: Exception => - repldbg("Error: complete(%s, %s) provoked %s".format(buf, cursor, ex)) - Candidates(cursor, List(" ", "")) + try tryAll + catch { case ex: Throwable => + repldbg("Error: complete(%s, %s) provoked".format(buf, cursor) + ex) + Candidates(cursor, + if (isReplDebug) List("") + else Nil + ) } } } -- cgit v1.2.3