Skip to content

manually defining _N methods in case class can produce Double definition error #9068

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
Rich2 opened this issue May 28, 2020 · 1 comment · Fixed by #9218
Closed

manually defining _N methods in case class can produce Double definition error #9068

Rich2 opened this issue May 28, 2020 · 1 comment · Fixed by #9218
Assignees
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug

Comments

@Rich2
Copy link

Rich2 commented May 28, 2020

case class MyClass(v1: Int, v2: Int, v3: Int) extends Product3[Int, Int, Int]
{ def _1: Int = v1
  def _2: Int = v2
  def _3: Int = v3
}
error] -- [E120] Naming Error: /Common/s2dotty/src/P4.scala:4:6 -----------------------
[error] 4 |{ def _1: Int = v1
[error]   |      ^
[error]   |      Double definition:
[error]   |      def _1: => Int in class MyClass at line 3 and
[error]   |      def _1: => Int in class MyClass at line 4
[error]   |      have the same type after erasure.

To be able to compile to Scala 2 and dotty without error. I'm guessing Dotty is automatically creating the _n properties. This would be great except those properties have to be defined explicitly for code cross compiling to 2.13.

Simple project to show this here

@liufengyun liufengyun added the area:desugar Desugaring happens after parsing but before typing, see desugar.scala label May 28, 2020
@bishabosha
Copy link
Member

bishabosha commented Jun 7, 2020

@bishabosha bishabosha changed the title Inheriting from Product classes produces duplication errors. manually defining _N methods in case class can produce Double definition error Jun 7, 2020
@odersky odersky self-assigned this Jun 8, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Jun 22, 2020
Don't generate _N selectors for case classes if a parameterless selector
is defined in same class.
@nicolasstucki nicolasstucki linked a pull request Jun 22, 2020 that will close this issue
nicolasstucki added a commit that referenced this issue Jun 22, 2020
Fix #9068: Don't duplicate _N selectors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants