summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala21
-rw-r--r--src/compiler/scala/tools/util/EditDistance.scala4
-rw-r--r--src/library/scala/collection/TraversableLike.scala2
-rw-r--r--test/files/run/t5387.scala15
5 files changed, 39 insertions, 7 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
diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala
index b4813e6341..36d45c0c8a 100644
--- a/src/library/scala/collection/TraversableLike.scala
+++ b/src/library/scala/collection/TraversableLike.scala
@@ -535,7 +535,7 @@ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr]
val b = newBuilder
var go = false
for (x <- this) {
- if (!p(x)) go = true
+ if (!go && !p(x)) go = true
if (go) b += x
}
b.result
diff --git a/test/files/run/t5387.scala b/test/files/run/t5387.scala
new file mode 100644
index 0000000000..5d62a005a9
--- /dev/null
+++ b/test/files/run/t5387.scala
@@ -0,0 +1,15 @@
+/*
+ * This tests that the predicate of dropWhile is only evaluated as often as needed, see https://issues.scala-lang.org/browse/SI-5387
+ */
+import scala.collection.immutable.ListMap
+object Test extends App{
+ val subject = ListMap(1->1,2->2,3->3,4->4,5->5)
+ val result = ListMap(3->3,4->4,5->5)
+ assert( result == subject.dropWhile{
+ case (key, value) => {
+ assert( key <= 3, "predicate evaluated more often than needed, key "+key )
+ key < 3
+ }
+ }
+ )
+}