-
Notifications
You must be signed in to change notification settings - Fork 21
case class copy method shouldn't subvert private constructor #7884
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7884?orig=1 |
@retronym said: I think the principled thing is to give the synthetic |
I made a repo to exercise and study this behavior a bit. Had been touched by it once or twice, last year, when I wanted to have a case class that only gets created internally. Had noticed that not defining the I agree with @scabug that "principled thing is to give the synthetic copy method the same access modifiers as the primary constructor." I would extend that to the created How to suggest this for 2.13? |
I think a pull request on this would likely be accepted. UPDATE: on the Discourse thread, @smarter suggests a SIP would be necessary. this is a modest enough change that involving the SIP committee seems like overkill to me, but, I'd bow to consensus on the subject |
I'll be likely to work on this in July. |
@SethTisue I'd be happy to make SIP, but plan to do so after I've got a PR with associated tests ready (hopefully this July). One reason to go SIP is that (to what I've seen so far) the current behaviour doesn't seem to be clearly defined, rather it "just is". I'll see that better when making changes to Scala, and if those changes don't break existing tests, that would useful information. |
The copy method is synthesized here: https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala#L176-L233. Its signature is completed by https://github.com/scala/scala/blob/2.13.x/src/compiler/scala/tools/nsc/typechecker/Namers.scala#L593-L616 EDIT: By the way, this is a tricky part of the compiler. Case in point: scala/scala#5730, which needed scala/scala#5845. (Fixed in 2.11.11 and 2.12.2) |
related: scala/scala3#5472 |
The text was updated successfully, but these errors were encountered: