-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest possible names in NotAMemberError
Fixes scala/bug#10181 With this change, NotAMemberError checks for possible members under target with edit distance of 2 or 1. ```scala scala> import scala.io.StdIn.{readline, readInt} ^ error: value readline is not a member of object scala.io.StdIn did you mean readLine? scala> import scala.io.stdin.{readLine => line} ^ error: object stdin is not a member of package io did you mean StdIn? scala> import scala.sth ^ error: object sth is not a member of package scala did you mean sys or math? ```
- Loading branch information
Showing
19 changed files
with
199 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package scala.tools.nsc | ||
package util | ||
|
||
import java.lang.Character.{ toLowerCase => lower } | ||
import scala.collection.immutable | ||
|
||
object EditDistance { | ||
|
||
/** | ||
* @author Paul Phillips | ||
* Translated from the java version at | ||
* http://www.merriampark.com/ld.htm | ||
* which is declared to be public domain. | ||
*/ | ||
def levenshtein( | ||
s: String, | ||
t: String, | ||
insertCost: Int = 1, | ||
deleteCost: Int = 1, | ||
subCost: Int = 1, | ||
matchCost: Int = 0, | ||
caseCost: Int = 1, | ||
transpositions: Boolean = false | ||
): Int = { | ||
val n = s.length | ||
val m = t.length | ||
if (n == 0) return m | ||
if (m == 0) return n | ||
|
||
val d = Array.ofDim[Int](n + 1, m + 1) | ||
0 to n foreach (x => d(x)(0) = x) | ||
0 to m foreach (x => d(0)(x) = x) | ||
|
||
for (i <- 1 to n; s_i = s(i - 1); j <- 1 to m) { | ||
val t_j = t(j - 1) | ||
val cost = if (s_i == t_j) matchCost else if (lower(s_i) == lower(t_j)) caseCost else subCost | ||
|
||
val c1 = d(i - 1)(j) + deleteCost | ||
val c2 = d(i)(j - 1) + insertCost | ||
val c3 = d(i - 1)(j - 1) + cost | ||
|
||
d(i)(j) = c1 min c2 min c3 | ||
|
||
if (transpositions) { | ||
if (i > 1 && j > 1 && s(i - 1) == t(j - 2) && s(i - 2) == t(j - 1)) | ||
d(i)(j) = d(i)(j) min (d(i - 2)(j - 2) + cost) | ||
} | ||
} | ||
|
||
d(n)(m) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package scala.tools.nsc | ||
package util | ||
|
||
import scala.collection.immutable.Seq | ||
|
||
trait StringUtil { | ||
def oxford(vs: Seq[String], conj: String): String = { | ||
vs match { | ||
case Seq() => "" | ||
case Seq(a) => a | ||
case Seq(a, b) => s"$a $conj $b" | ||
case xs => xs.dropRight(1).mkString(", ") + s", $conj " + xs.last | ||
} | ||
} | ||
} | ||
|
||
object StringUtil extends StringUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Macros_Test_2.scala:2: error: value foo2 is not a member of object Impls | ||
did you mean foo? | ||
def foo(x: Any) = macro Impls.foo2 | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
noMember1.scala:1: error: object IterableOnceOps is not a member of package collection | ||
Note: trait IterableOnceOps exists, but it has no companion object. | ||
note: trait IterableOnceOps exists, but it has no companion object. | ||
import scala.collection.IterableOnceOps._ | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
noMember2.scala:2: error: object IterableOnceOps is not a member of package collection | ||
Note: trait IterableOnceOps exists, but it has no companion object. | ||
note: trait IterableOnceOps exists, but it has no companion object. | ||
val m = scala.collection.IterableOnceOps(1, 2, 3) | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
suggest-similar.scala:8: error: not found: value flippitx | ||
flippitx = 123 | ||
^ | ||
suggest-similar.scala:9: error: not found: value identiyt | ||
suggest-similar.scala:10: error: value flippitx is not a member of object example.Weehawken | ||
did you mean flippity? | ||
Weehawken.flippitx = 123 | ||
^ | ||
suggest-similar.scala:11: error: not found: value identiyt | ||
Nil map identiyt | ||
^ | ||
suggest-similar.scala:10: error: not found: type Bingus | ||
new Bingus | ||
^ | ||
three errors found | ||
suggest-similar.scala:12: error: type Eeehawken is not a member of package example | ||
did you mean Weehawken? | ||
new example.Eeehawken | ||
^ | ||
suggest-similar.scala:16: error: value readline is not a member of object scala.io.StdIn | ||
did you mean readLine? | ||
import scala.io.StdIn.{readline, readInt} | ||
^ | ||
suggest-similar.scala:20: error: object stdin is not a member of package io | ||
did you mean StdIn? | ||
import scala.io.stdin.{readLine => line} | ||
^ | ||
suggest-similar.scala:37: error: value foo is not a member of object example.Hohokus | ||
did you mean foo1, foo2, foo3, or foo4? | ||
Hohokus.foo | ||
^ | ||
suggest-similar.scala:41: error: value bar is not a member of example.Hohokus | ||
did you mean bar2? | ||
new Hohokus().bar // don't suggest bar1 | ||
^ | ||
7 errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
class Dingus | ||
object Dingus { | ||
package example | ||
|
||
class Weehawken | ||
object Weehawken { | ||
var flippity = 1 | ||
type Blippitx = Int | ||
} | ||
import Dingus._ | ||
|
||
class A { | ||
flippitx = 123 | ||
Weehawken.flippitx = 123 | ||
Nil map identiyt | ||
new Bingus | ||
new example.Eeehawken | ||
} | ||
|
||
object B { | ||
import scala.io.StdIn.{readline, readInt} | ||
} | ||
|
||
object C { | ||
import scala.io.stdin.{readLine => line} | ||
} | ||
|
||
class Hohokus { | ||
protected def bar1 | ||
protected[example] def bar2 | ||
} | ||
object Hohokus { | ||
def foo1 = 1 | ||
def foo2 = 2 | ||
def foo3 = 3 | ||
def foo4 = 4 | ||
def foo5 = 5 | ||
def foo6 = 6 | ||
} | ||
|
||
object D { | ||
Hohokus.foo | ||
} | ||
|
||
object E { | ||
new Hohokus().bar // don't suggest bar1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
t3346c.scala:60: error: value bar is not a member of Either[Int,String] | ||
did you mean map? | ||
eii.bar | ||
^ | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
scala.Predef.ArrowAssoc[Int](1).->[Int](2) | ||
scala.reflect.macros.TypecheckException: value -> is not a member of Int | ||
did you mean >>>? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters