Skip to content

reflect.Selectable does not mangle operator names #4528

Open
@Blaisorblade

Description

@Blaisorblade
scala>     type T = {val a: Int; def a_=(x: Int): Unit}
// defined alias type T = Object{a: Int; a_=(x: Int): Unit}

scala> import scala.reflect.Selectable.reflectiveSelectable

scala> (new {var a = 10}: T).a = 11
java.lang.NoSuchMethodException: rs$line$3$$anon$1.a_=(int)
	at java.lang.Class.getMethod(Class.java:1786)
	at scala.reflect.Selectable$.selectDynamicMethod$extension(Selectable.scala:20)
	at scala.reflect.Selectable.selectDynamicMethod(Selectable.scala:17)
	at rs$line$3$.<init>(rs$line$3:1)
	at rs$line$3$.<clinit>(rs$line$3)
	at rs$line$3.res0(rs$line$3)

Haven't tried other characters.

Decompiling a bigger example reminds us that the generated method is called a_$eq and not a_=, while the generated code indeed tries to call a_= (per jad decompilation):

        ((Function1)Selectable$.MODULE$.reflectiveSelectable(v).selectDynamicMethod("a_=", Predef$.MODULE$.wrapRefArray(new ClassTag[] {
            ClassTag$.MODULE$.apply(Integer.TYPE)
        }))).apply(BoxesRunTime.boxToInteger(11));

Since structural types are intended to be mapped also to other backends (see applications to databases in #1886), it's not clear the encoding should be done by the compiler; we might want to mangle the name inside reflectiveSelectable.

EDIT: Discovered while testing fix to #4496 and checking all variants.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions