Skip to content

operator identifier with some characters from Unicode Sm and So categories can't be injected into string literal #12484

Closed
scala/scala
#9805
@unkarjedy

Description

@unkarjedy

Scala 2.13.7

from https://www.scala-lang.org/files/archive/spec/2.13/13-syntax-summary.html

opchar           ::=  ‘!’ | ‘#’ | ‘%’ | ‘&’ | ‘*’ | ‘+’ | ‘-’ | ‘/’ | ‘:’ |
                      ‘<’ | ‘=’ | ‘>’ | ‘?’ | ‘@’ | ‘\’ | ‘^’ | ‘|’ | ‘~’
                      and any character in Unicode categories Sm or So
...
op               ::=  opchar {opchar}
plainid          ::=  ... |  op
id               ::=  plainid |  ...
...
interpolatedStringPart  ::= printableChar \ (‘"’ | ‘$’ | ‘\’) | escape
escape                  ::=  ... |  ‘\$’ id |  ...

Example code

//noinspection TypeAnnotation,NotImplementedCode
class Wrapper2 {
  val  = 1 // category: So other
  val  = 1 // category: Sm math
  val 𝓅 = 1 // category: Ll math (suppl)
  val 𐐀 = 1 // category: Lu (suppl)

  s"$⚕" // bad
  s"$" // bad
  s"$𝓅" // ok
  s"$𐐀" // ok
}

Expected
No compilation errors due to spec ^

Actual

invalid string interpolation $⨀, expected: $$, $", $identifier or ${expression}
invalid string interpolation $⚕, expected: $$, $", $identifier or ${expression}

It compiles fine with ${...} injector though:

s"${}" // ok
s"${}" // ok
s"${𝓅}" // ok
s"${𐐀}" // ok

relates to:
#12482
#1406
scala/scala#9687

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions