Skip to content

Commit d14de3d

Browse files
committed
fix #1779: support $_ and $_id in interpolated string
1 parent ac160ea commit d14de3d

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ object Parsers {
625625
atPos(in.offset) {
626626
if (in.token == IDENTIFIER)
627627
termIdent()
628+
else if (in.token == USCORE) {
629+
in.nextToken()
630+
Ident(nme.WILDCARD)
631+
}
628632
else if (in.token == THIS) {
629633
in.nextToken()
630634
This(EmptyTypeIdent)

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ object Scanners {
758758
finishStringPart()
759759
nextRawChar()
760760
next.token = LBRACE
761-
} else if (Character.isUnicodeIdentifierStart(ch)) {
761+
} else if (Character.isUnicodeIdentifierStart(ch) || ch == '_') {
762762
finishStringPart()
763763
do {
764764
putChar(ch)

tests/run/i1779.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends

tests/run/i1779.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object Test {
2+
implicit class Foo(sc: StringContext) {
3+
object q {
4+
def unapply(arg: Any): Option[(Any, Any)] =
5+
Some((sc.parts(0), sc.parts(1)))
6+
}
7+
}
8+
9+
def main(args: Array[String]): Unit = {
10+
val q"class $_ extends $_parent" = new Object
11+
println(_parent)
12+
}
13+
}

0 commit comments

Comments
 (0)