Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
megatroninho opened this issue Nov 2, 2021 · 0 comments · Fixed by #14081
Closed
Assignees
Labels
itype:bug Spree Suitable for a future Spree
Milestone

Comments

@megatroninho
Copy link

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.

@anatoliykmetyuk anatoliykmetyuk added the Spree Suitable for a future Spree label Nov 10, 2021
odersky added a commit to dotty-staging/dotty that referenced this issue Dec 9, 2021
There needs to be a special alignment of planetary body to obtain two fields
that have different names for Dotty (one has a FieldName, the other a regular name),
but that still map to the same underlying name. This is now detected and resolved.

Fixes scala#13862
anatoliykmetyuk pushed a commit to dotty-staging/dotty that referenced this issue Dec 17, 2021
There needs to be a special alignment of planetary body to obtain two fields
that have different names for Dotty (one has a FieldName, the other a regular name),
but that still map to the same underlying name. This is now detected and resolved.

Fixes scala#13862
anatoliykmetyuk pushed a commit to dotty-staging/dotty that referenced this issue Dec 17, 2021
There needs to be a special alignment of planetary body to obtain two fields
that have different names for Dotty (one has a FieldName, the other a regular name),
but that still map to the same underlying name. This is now detected and resolved.

Fixes scala#13862
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
There needs to be a special alignment of planetary body to obtain two fields
that have different names for Dotty (one has a FieldName, the other a regular name),
but that still map to the same underlying name. This is now detected and resolved.

Fixes scala#13862
@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants