Open
Description
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