Skip to content
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

Synthetic copy generated when provided one is present #22038

Open
OndrejSpanel opened this issue Nov 27, 2024 · 1 comment
Open

Synthetic copy generated when provided one is present #22038

OndrejSpanel opened this issue Nov 27, 2024 · 1 comment

Comments

@OndrejSpanel
Copy link
Member

Compiler version

3.0.0
3.5.2

Minimized code

object Main {
  case class F(state: String, ext: Int) {
    def copy(state: Char): F = F(state.toString, ext)
  }

  def main(args: Array[String]): Unit = {
    val f = F("A", 0)
    println(f.copy('B'))
    println(f.copy("B", 2))
  }
}

Output

F(B,0)
F(B,2)

Expectation

The second variant should not compile, as it does not compile in Scala 2.13.15.

Specs say in https://scala-lang.org/files/archive/spec/3.4/05-classes-and-objects.html:

A method named copy is implicitly added to every case class unless the class already has a member (directly defined or inherited) with that name

It seems compiler adds a synthetic copy in spite of one being defined by me. If this is intended, documentation should be updated, but I do not remember reading about such change from Scala 2 to Scala 3.

Note

This was encountered in softwaremill/quicklens#256

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 27, 2024
@KacperFKorban
Copy link
Member

This was discussed at the compiler meeting today. The conclusion was that Scala 3 behavior is correct, so this is probably a spec issue.
CC: @sjrd

@KacperFKorban KacperFKorban added area:spec and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants