Skip to content

Commit

Permalink
A little help for what's changed
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Mar 8, 2021
1 parent 9eb0f73 commit 9967206
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Expand Up @@ -854,7 +854,12 @@ trait Scanners extends ScannersCommon {
} else unclosedStringLit()
}

private def unclosedStringLit(): Unit = syntaxError("unclosed string literal")
private def unclosedStringLit(seenEscapedQuoteInInterpolation: Boolean = false): Unit = {
val note =
if (seenEscapedQuoteInInterpolation) "; note that `\\\"` no longer closes single-quoted interpolated string literals since 2.13.6, you can use a triple-quoted string instead"
else ""
syntaxError(s"unclosed string literal$note")
}

private def replaceUnicodeEscapesInTriple(): Unit =
if(strVal != null) {
Expand Down Expand Up @@ -890,7 +895,8 @@ trait Scanners extends ScannersCommon {
}
}

@tailrec private def getStringPart(multiLine: Boolean): Unit = {
// for interpolated strings
@tailrec private def getStringPart(multiLine: Boolean, seenEscapedQuote: Boolean = false): Unit = {
def finishStringPart() = {
setStrVal()
token = STRINGPART
Expand All @@ -904,7 +910,7 @@ trait Scanners extends ScannersCommon {
setStrVal()
token = STRINGLIT
} else
getStringPart(multiLine)
getStringPart(multiLine, seenEscapedQuote)
} else {
nextChar()
setStrVal()
Expand All @@ -913,17 +919,18 @@ trait Scanners extends ScannersCommon {
} else if (ch == '\\' && !multiLine) {
putChar(ch)
nextRawChar()
if (ch == '"' || ch == '\\') {
val q = ch == '"'
if (q || ch == '\\') {
putChar(ch)
nextRawChar()
}
getStringPart(multiLine)
getStringPart(multiLine, seenEscapedQuote || q)
} else if (ch == '$') {
nextRawChar()
if (ch == '$') {
putChar(ch)
nextRawChar()
getStringPart(multiLine)
getStringPart(multiLine, seenEscapedQuote)
} else if (ch == '{') {
finishStringPart()
nextRawChar()
Expand Down Expand Up @@ -953,13 +960,14 @@ trait Scanners extends ScannersCommon {
if (isUnclosedLiteral) {
if (multiLine)
incompleteInputError("unclosed multi-line string literal")
else
unclosedStringLit()
else {
unclosedStringLit(seenEscapedQuote)
}
}
else {
putChar(ch)
nextRawChar()
getStringPart(multiLine)
getStringPart(multiLine, seenEscapedQuote)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/t6476.check
@@ -1,4 +1,4 @@
t6476.scala:8: error: unclosed string literal
t6476.scala:8: error: unclosed string literal; note that `\"` no longer closes single-quoted interpolated string literals since 2.13.6, you can use a triple-quoted string instead
mimi"\"
^
1 error

0 comments on commit 9967206

Please sign in to comment.