Skip to content

Commit

Permalink
Allow two trailing slashes, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Mar 8, 2021
1 parent 47680cb commit b7ceda5
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 18 deletions.
16 changes: 5 additions & 11 deletions src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Expand Up @@ -910,20 +910,14 @@ trait Scanners extends ScannersCommon {
setStrVal()
token = STRINGLIT
}
} else if (ch == '\\') {
if (multiLine) {
putChar(ch)
nextRawChar()
getStringPart(multiLine)
} else {
} else if (ch == '\\' && !multiLine) {
putChar(ch)
nextRawChar()
if (ch == '"' || ch == '\\') {
putChar(ch)
nextRawChar()
if (ch == '"') {
putChar(ch)
nextRawChar()
}
getStringPart(multiLine)
}
getStringPart(multiLine)
} else if (ch == '$') {
nextRawChar()
if (ch == '$') {
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t6476.check
@@ -0,0 +1,4 @@
t6476.scala:8: error: unclosed string literal
mimi"\"
^
1 error
9 changes: 9 additions & 0 deletions test/files/neg/t6476.scala
@@ -0,0 +1,9 @@
// only the last one doesn't parse
class C {
mimi"""\ """
mimi"""\\"""
mimi"""\"""
mimi"\ "
mimi"\\"
mimi"\"
}
7 changes: 7 additions & 0 deletions test/files/neg/t6476b.check
@@ -0,0 +1,7 @@
t6476b.scala:2: error: invalid escape at terminal index 0 in "\". Use \\ for literal \.
val sa = s"""\"""
^
t6476b.scala:4: error: invalid escape '\ ' not one of [\b, \t, \n, \f, \r, \\, \", \', \uxxxx] at index 0 in "\ ". Use \\ for literal \.
val sc = s"""\ """
^
2 errors
8 changes: 8 additions & 0 deletions test/files/neg/t6476b.scala
@@ -0,0 +1,8 @@
class C {
val sa = s"""\"""
val sb = s"""\\"""
val sc = s"""\ """
val ra = raw"""\"""
val rb = raw"""\\"""
val rc = raw"""\ """
}
1 change: 0 additions & 1 deletion test/files/run/string-interpolator.check

This file was deleted.

6 changes: 0 additions & 6 deletions test/files/run/string-interpolator.scala

This file was deleted.

9 changes: 9 additions & 0 deletions test/files/run/t6476.check
@@ -0,0 +1,9 @@
"Hello", Alice
"Hello", Alice
"Hello", Alice
"Hello", Alice
\"Hello\", Alice
\"Hello\", Alice
\TILT\
\TILT\
\\TILT\\
17 changes: 17 additions & 0 deletions test/files/run/t6476.scala
@@ -0,0 +1,17 @@
object Test {
def main(args: Array[String]): Unit = {
val person = "Alice"
println(s"\"Hello\", $person")
println(s"""\"Hello\", $person""")

println(f"\"Hello\", $person")
println(f"""\"Hello\", $person""")

println(raw"\"Hello\", $person")
println(raw"""\"Hello\", $person""")

println(s"\\TILT\\")
println(f"\\TILT\\")
println(raw"\\TILT\\")
}
}

0 comments on commit b7ceda5

Please sign in to comment.