Skip to content

Commit e95df7d

Browse files
committed
REPL completion for idents starting with number
This relaxes some of the completion result filtering to allow backticked identifiers such as the following to show up in completion results. object Test { def `1 world` = "" } The pathological builtin names to guard against all start with `<`, even in their encoded forms (backticked `<` would start with a `$`). Fixes scala/bug#13076
1 parent 360d5da commit e95df7d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import scala.collection.mutable
2121
import scala.collection.mutable.{HashSet, LinkedHashMap}
2222
import scala.jdk.javaapi.CollectionConverters
2323
import scala.language.implicitConversions
24-
import scala.reflect.internal.Chars.isIdentifierStart
2524
import scala.reflect.internal.util.SourceFile
2625
import scala.tools.nsc.io.AbstractFile
2726
import scala.tools.nsc.reporters.Reporter
@@ -1191,7 +1190,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
11911190
results.filter { (member: Member) =>
11921191
val symbol = member.sym
11931192
def isStable = member.tpe.isStable || member.sym.isStable || member.sym.getterIn(member.sym.owner).isStable
1194-
def isJunk = !symbol.exists || symbol.name.isEmpty || !isIdentifierStart(member.sym.name.charAt(0)) // e.g. <byname>
1193+
def isJunk = !symbol.exists || symbol.name.isEmpty || symbol.encodedName.charAt(0) == '<' // e.g. <byname>
11951194
def nameTypeOk: Boolean = {
11961195
forImport || // Completing an import: keep terms and types.
11971196
symbol.name.isTermName == name.isTermName || // Keep names of the same type
@@ -1202,7 +1201,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
12021201
matcher(member.aliasInfo.map(_.sym.name).getOrElse(NoSymbol.name)) && !forImport && symbol.name.isTermName == name.isTermName
12031202
}
12041203

1205-
!isJunk && member.accessible && !symbol.isConstructor && (name.isEmpty || (matcher(member.sym.name) || aliasTypeOk)
1204+
!isJunk && member.accessible && (name.isEmpty || (matcher(member.sym.name) || aliasTypeOk)
12061205
&& nameTypeOk)
12071206

12081207
}

test/junit/scala/tools/nsc/interpreter/CompletionTest.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class CompletionTest {
9494
checkExact(completer, "object O { private def x_y_z = 1; x_y", "}")("x_y_z")
9595
checkExact(completer, "object x_y_z; import x_y")("x_y_z")
9696

97+
checkExact(completer, "object O { def `1 thing` = 1 }; O.")("1 thing")
98+
checkExact(completer, "object O { def `<x>` = 1 }; O.")("<x>")
99+
97100
checkExact(completer, "object x_y_z { def a_b_c }; import x_y_z.a_b")("a_b_c")
98101

99102
checkExact(completer, "object X { private[this] def definition = 0; def")("definition")

0 commit comments

Comments
 (0)