Skip to content

No generic signature emitted for trait getter #6350

Open
@smarter

Description

@smarter

Given:

trait Foo {
  val bla: List[String] = List("foo")
}
class Bar extends Foo

Decompiling with cfr shows:

public interface Foo {
    default public void $init$() {
    }

    public List<String> bla();

    default public List initial$bla() {
        return package$.MODULE$.List().apply((Seq)Predef$.MODULE$.wrapRefArray((Object[])new String[]{"foo"}));
    }
}
public class Bar
implements Foo {
    private final List bla;

    public Bar() {
        this.bla = Foo.super.initial$bla();
        Foo.super.$init$();
    }

    public List bla() {
        return this.bla;
    }
}

Notice the lack of generic signature on bla() in Bar, since trait getters are emitted in Mixin after erasure, getting a generic signature is not trivial. For mixin forwarders we work around this by emitting them as bridges (cf 6d0f9ca), but we should probably not do that for trait setters since they are not legitimately bridges.

We could also try to move trait getter (and setter, and maybe more stuff) before erasure since that's what scalac appear to be doing.

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