Skip to content

Identical parameter name in trait and extending class results in ClassFormatError #13862

Closed
@megatroninho

Description

@megatroninho

Compiler version

3.1.0

Minimized code

trait Foo(val num: Int)                 // a trait with a parameter stored in a val

class Bar(num: Int) extends Foo(num):   // an extending class with a parameter of the same name
  def bar = this.num                    // implicitly creates another num in Bar

Bar(123)                                

Output

Compiles, but the program crashes when run:

java.lang.ClassFormatError: Duplicate field name "num" with signature "I" 

Expectation

I would expect the code to compile, not crash, and produce a Bar object just like it does if Foo is a class rather than a trait.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions