Skip to content

Commit

Permalink
allow $ escaping double quotes in interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnhoekstra committed Mar 8, 2021
1 parent 262f6e9 commit f089d05
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ trait Scanners extends ScannersCommon {
}
} else if (ch == '$') {
nextRawChar()
if (ch == '$') {
if (ch == '$' || ch == '"') {
putChar(ch)
nextRawChar()
getStringPart(multiLine)
Expand All @@ -938,7 +938,8 @@ trait Scanners extends ScannersCommon {
next.token = kwArray(idx)
}
} else {
syntaxError(s"invalid string interpolation $$$ch, expected: $$$$, $$identifier or $${expression}")
val expectations = "$$, $\", $identifier or ${expression}"
syntaxError(s"invalid string interpolation $$$ch, expected: $expectations")
}
} else {
val isUnclosedLiteral = (ch == SU || (!multiLine && (ch == CR || ch == LF)))
Expand Down
7 changes: 2 additions & 5 deletions test/files/neg/t5856.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
t5856.scala:10: error: invalid string interpolation $", expected: $$, $identifier or ${expression}
val s9 = s"$"
^
t5856.scala:10: error: unclosed string literal
val s9 = s"$"
^
^
t5856.scala:2: error: error in interpolated string: identifier or block expected
val s1 = s"$null"
^
Expand All @@ -28,4 +25,4 @@ t5856.scala:8: error: error in interpolated string: identifier or block expected
t5856.scala:9: error: error in interpolated string: identifier or block expected
val s8 = s"$super"
^
10 errors
9 errors found
4 changes: 4 additions & 0 deletions test/files/pos/quoteescape3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// scalac: -Xsource:3
object Test {
val escaped = s"$"everybody loves escaped quotes$" is a common sentiment."
}

0 comments on commit f089d05

Please sign in to comment.