diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 21 | ||||
-rw-r--r-- | src/compiler/scala/tools/util/EditDistance.scala | 4 |
3 files changed, 23 insertions, 6 deletions
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 5aaad9da2f..0fbde03e97 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3801,6 +3801,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) @@ -3915,9 +3918,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)) @@ -3930,8 +3942,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { ) similarString("" + name, allowedStrings) } - else "" - ) + } error(tree.pos, "not found: "+decodeWithKind(name, context.owner) + similar) } } diff --git a/src/compiler/scala/tools/util/EditDistance.scala b/src/compiler/scala/tools/util/EditDistance.scala index 5067dce384..5f152ecabb 100644 --- a/src/compiler/scala/tools/util/EditDistance.scala +++ b/src/compiler/scala/tools/util/EditDistance.scala @@ -7,6 +7,8 @@ package scala.tools package util object EditDistance { + import java.lang.Character.{ toLowerCase => lower } + def similarString(name: String, allowed: TraversableOnce[String]): String = { val suggested = suggestions(name, allowed.toSeq, maxDistance = 1, maxSuggestions = 2) if (suggested.isEmpty) "" @@ -46,7 +48,7 @@ object EditDistance { var j = 1 while (j <= m) { val t_j = t(j - 1) - val cost = if (s_i == t_j) 0 else 1 + val cost = if (lower(s_i) == lower(t_j)) 0 else 1 val c1 = d(i - 1)(j) + 1 val c2 = d(i)(j - 1) + 1 |