Skip to content

Commit aeb01c8

Browse files
authored
Merge pull request scala#5236 from som-snytt/issue/triple-backport
[nomerge] Avoid triple-quoting triple quotes
2 parents aaf7bc0 + a6ce8e3 commit aeb01c8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/reflect/scala/reflect/internal/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
10501050
x match {
10511051
case Constant(v: String) if {
10521052
val strValue = x.stringValue
1053-
strValue.contains(LF) && strValue.contains("\"\"\"") && strValue.size > 1
1053+
strValue.contains(LF) && !strValue.contains("\"\"\"") && strValue.size > 1
10541054
} =>
10551055
val splitValue = x.stringValue.split(s"$LF").toList
10561056
val multilineStringValue = if (x.stringValue.endsWith(s"$LF")) splitValue :+ "" else splitValue

test/junit/scala/reflect/internal/PrintersTest.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ trait BasePrintTests {
8686

8787
@Test def testConstantLong = assertTreeCode(Literal(Constant(42l)))("42L")
8888

89+
@Test def testConstantMultiline = assertTreeCode(Literal(Constant("hello\nworld")))("\"\"\"hello\nworld\"\"\"")
90+
91+
val sq = "\""
92+
val teq = "\\\"" * 3
93+
val tq = "\"" * 3
94+
95+
@Test def testConstantEmbeddedTriple = assertTreeCode(Literal(Constant(s"${tq}hello${tq}\nworld")))(s"${sq}${teq}hello${teq}\\nworld${sq}")
96+
8997
@Test def testOpExpr = assertPrintedCode("(5).+(4)", checkTypedTree = false)
9098

9199
@Test def testName1 = assertPrintedCode("class test")

0 commit comments

Comments
 (0)