Skip to content

Commit

Permalink
Merge pull request #9139 from chaitanyav/2.13.x
Browse files Browse the repository at this point in the history
CodePrinter prints backquoted names
  • Loading branch information
lrytz committed Jul 28, 2020
2 parents 7db39c6 + 828defb commit 7dbf0ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Printers.scala
Expand Up @@ -562,7 +562,7 @@ trait Printers extends api.Printers { self: SymbolTable =>

def addBackquotes(s: String) =
if (decoded && (decName.exists(ch => brackets.contains(ch) || isWhitespace(ch) || isDot(ch)) ||
(name.isOperatorName && decName.exists(isOperatorPart) && decName.exists(isScalaLetter) && !decName.contains(bslash))))
((name.isOperatorName || decName.exists(isOperatorPart)) && decName.exists(isScalaLetter) && !decName.contains(bslash))))
s"`$s`" else s

if (name == nme.CONSTRUCTOR) "this"
Expand Down
4 changes: 4 additions & 0 deletions test/junit/scala/reflect/internal/PrintersTest.scala
Expand Up @@ -137,6 +137,10 @@ class BasePrintTest {

@Test def testName21 = assertPrintedCode("""class `test.name`""")

@Test def testName22 = assertEquals("val `some-val`: Int = 1", showCode(q"""val ${TermName("some-val")}: Int = 1"""))

@Test def testName23 = assertEquals("val `some+`: String = \"foo\"", showCode(q"""val ${TermName("some+")}: String = "foo""""))

@Test def testIfExpr1 = assertResultCode(code = sm"""
|val a = 1
|if (a > 1)
Expand Down

0 comments on commit 7dbf0ad

Please sign in to comment.