Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow trailing backslash in string interpolators #8942

Merged
merged 1 commit into from May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 19 additions & 18 deletions src/library/scala/StringContext.scala
Expand Up @@ -389,7 +389,7 @@ object StringContext {

protected[scala] def processUnicode(str: String): String =
str indexOf "\\" match {
case i if i == -1 || i >= (str.length() - 5) => str
lrytz marked this conversation as resolved.
Show resolved Hide resolved
case i if i == -1 || i >= (str.length() - 5) => str
case i => replaceU(str, i)
}

Expand Down Expand Up @@ -438,27 +438,28 @@ object StringContext {
if (next >= 0) {
//require(str(next) == '\\')
if (next > i) b.append(str, i, next)
var idx = next + 1
if (idx >= len) {
b.toString()
}
else {
val (ch, advance) = str(idx) match {
case 'u' => readUEscape(str, idx)
case chr => {
b.append('\\')
(chr, 1)
}
var idx = next + 1
lrytz marked this conversation as resolved.
Show resolved Hide resolved
if (idx >= len) {
if (idx == len) b.append('\\')
lrytz marked this conversation as resolved.
Show resolved Hide resolved
b.toString()
}
else {
val (ch, advance) = str(idx) match {
case 'u' => readUEscape(str, idx)
case chr => {
b.append('\\')
(chr, 1)
}
idx += advance
b append ch
loop(idx, str.indexOf('\\', idx))
}
} else {
if (i < len) b.append(str, i, len)
b.toString
idx += advance
b.append(ch)
loop(idx, str.indexOf('\\', idx))
}
} else {
if (i < len) b.append(str, i, len)
b.toString()
}
}
loop(0, first)
}

Expand Down
7 changes: 7 additions & 0 deletions test/files/pos/t11966.scala
@@ -0,0 +1,7 @@
// scalac: -Werror -deprecation
//
object Test {
val original = """\/ \/ /\"""
val minimal = """\1234\"""
val alternative = raw"\1234\"
}
6 changes: 3 additions & 3 deletions test/files/run/literals.scala
Expand Up @@ -28,11 +28,11 @@ object Test {
check_success("'\\u005f' == '_'", '\u005f', '_')

//unicode escapes escape in interpolations
check_success("bleh", s"\u0024", "$")
check_success("bleh", s"""\u0024""", "$")
check_success("""s"\\u0024" == "$"""", s"\u0024", "$")
check_success("s\"\"\"\\u0024\"\"\" == \"$\"", s"""\u0024""", "$")


//Int#asInstanceOf[Char] gets the char at the codepont
//Int#asInstanceOf[Char] gets the char at the codepoint
check_success("65.asInstanceOf[Char] == 'A'", 65.asInstanceOf[Char], 'A')

// boolean
Expand Down