From 8deade7d868dbd79194621d815ee6eee46f9807d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 19 Jan 2012 11:25:19 -0800 Subject: Avoid calculating similar strings sometimes. Like when they're useless. As per suggestion from moors. Closes SI-5382. --- .../scala/tools/nsc/typechecker/Contexts.scala | 4 ++++ .../scala/tools/nsc/typechecker/Typers.scala | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index f199195b81..faff4ccab2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -122,6 +122,10 @@ trait Contexts { self: Analyzer => var typingIndentLevel: Int = 0 def typingIndent = " " * typingIndentLevel + def enclClassOrMethod: Context = + if ((owner eq NoSymbol) || (owner.isClass) || (owner.isMethod)) this + else outer.enclClassOrMethod + def undetparamsString = if (undetparams.isEmpty) "" else undetparams.mkString("undetparams=", ", ", "") diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 884ad7af3d..b4221365be 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3800,6 +3800,9 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { var cx = startingIdentContext while (defSym == NoSymbol && cx != NoContext) { + // !!! Shouldn't the argument to compileSourceFor be cx, not context? + // I can't tell because those methods do nothing in the standard compiler, + // presumably they are overridden in the IDE. currentRun.compileSourceFor(context.asInstanceOf[analyzer.Context], name) pre = cx.enclClass.prefix defEntry = cx.scope.lookupEntry(name) @@ -3914,9 +3917,18 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { // Avoiding some spurious error messages: see SI-2388. if (reporter.hasErrors && (name startsWith tpnme.ANON_CLASS_NAME)) () else { - val similar = ( - // name length check to limit unhelpful suggestions for e.g. "x" and "b1" - if (name.length > 2) { + // This laborious determination arrived at to keep the tests working. + val calcSimilar = ( + name.length > 2 && ( + startingIdentContext.reportGeneralErrors + || startingIdentContext.enclClassOrMethod.reportGeneralErrors + ) + ) + // avoid calculating if we're in "silent" mode. + // name length check to limit unhelpful suggestions for e.g. "x" and "b1" + val similar = { + if (!calcSimilar) "" + else { val allowed = ( startingIdentContext.enclosingContextChain flatMap (ctx => ctx.scope.toList ++ ctx.imports.flatMap(_.allImportedSymbols)) @@ -3929,8 +3941,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { ) similarString("" + name, allowedStrings) } - else "" - ) + } error(tree.pos, "not found: "+decodeWithKind(name, context.owner) + similar) } } -- cgit v1.2.3