I have a class extending Selectable with type refinement. I have a problem with symbol names like < or { because the argument passed to selectDynamic method is $less $u0028`. What is the algorithm of the name normalisation?
I tried to create a ValDef with metaprogramming and access its name, but it stil gives my the symbolic one (like <)
my simplified code:
trait HelperTrait extends Selectable:
def selectDynamic(name: String): Any
val x: HelperTrait & {
def + : String
def < : String
def `{`: String
} = new HelperTrait:
val + = "1"
val < = "2"
val `{` = "3"
def selectDynamic(name: String): Any = name match
case "+" => this.+
case "<" => this.<
case "{" => this.`{`
test("+") {
assert(x.+ == "1")
}
test("<") {
assert(x.< == "2")
}
test("{") {
assert(x.`{` == "3")
}
results in
- + *** FAILED ***
[166-07] scala.MatchError: $plus (of class java.lang.String)
[166-07] at <test path>$$anon$1.selectDynamic(x.scala:25)
[166-07] ...
[166-07] - < *** FAILED ***
[166-07] scala.MatchError: $less (of class java.lang.String)
[166-07] at <test path>$$anon$1.selectDynamic(x.scala:25)
[166-07] ...
[166-07] ...
[166-07] - { *** FAILED ***
[166-07] scala.MatchError: $u007B (of class java.lang.String)
[166-07] at <test path>$$anon$1.selectDynamic(x.scala:25)
[166-07] ...
OK. I’ve found scala.reflect.NameTransformer.decode which transform $less back to <. Imo, any doc referencing this behaviour would be useful
4 Likes