Skip to content

Traits do not have static forwarders in bytecode #7328

Closed
@bishabosha

Description

@bishabosha

minimized code

compile with dotc 19.0-RC1

trait Foo { def foo: String = "foo" }

compile with scalacenter/scala@a8f11ef

object TestFoo {
  def main(args: Array[String]): Unit = {
    assert(new Foo {}.foo == "foo")
  }
}

runtime error:

Exception in thread "main" java.lang.NoSuchMethodError: Foo.foo$(LFoo;)Ljava/lang/String;
	at TestFoo$$anon$1.foo(TestFoo.scala:5)
	at TestFoo$.main(TestFoo.scala:5)
	at TestFoo.main(TestFoo.scala)
        ...

expectation

Anonymous subclasses of traits generated by Scala 2.13.x implement methods by calling a static forwarder on the generated Interface.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions