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 be864c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Expand Up @@ -912,7 +912,7 @@ trait Scanners extends ScannersCommon {
}
} else if (ch == '$') {
nextRawChar()
if (ch == '$') {
if (ch == '$' || (currentRun.isScala3 && ch == '"')) {
putChar(ch)
nextRawChar()
getStringPart(multiLine)
Expand All @@ -938,7 +938,10 @@ trait Scanners extends ScannersCommon {
next.token = kwArray(idx)
}
} else {
syntaxError(s"invalid string interpolation $$$ch, expected: $$$$, $$identifier or $${expression}")
val expectations =
if (currentRun.isScala3) "$$, $\", $identifier or ${expression}"
else "$$, $identifier or ${expression}"
syntaxError(s"invalid string interpolation $$$ch, expected: $expectations")
}
} else {
val isUnclosedLiteral = (ch == SU || (!multiLine && (ch == CR || ch == LF)))
Expand Down
4 changes: 4 additions & 0 deletions test/files/pos/quoteescape3.scala
@@ -0,0 +1,4 @@
// scalac: -Xsource:3
object Test {
val escaped = s"$"everybody loves escaped quotes$" is a common sentiment."
}

0 comments on commit be864c3

Please sign in to comment.