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
Case class copy and apply inherit access modifiers from constructor (under -Xsource:3) #7702
Conversation
This comment has been minimized.
This comment has been minimized.
Added some changes to bring the PR in line with scala/scala3#5830 and fixes for corresponding dotty issues scala/scala3#5857 and scala/scala3#5859. |
@adriaanm All those private constructors in |
IIRC it's to control who can create an instance of a class -- if this is what you want, a private constructor is useless if your apply is public, so basically the same as what your PR offers by default :-) |
@adriaanm Err... Not following 100% what you're saying. Some of those tests seem to rely specifically on the generated But anyway I think this PR is ready for review and discussion on how to proceed (SIP or no SIP, -Xsource flag or no flag, ...). Status of this PR right now:
I reviewed all failing tests and the bugs they are defending against. In all cases the right thing to do seemed to me turning private constructors into protected. That way |
@smarter Is there a SIP for this on Dotty's change? |
There isn't. |
I wasn't aware of this PR until just now. It would be really nice to get this into Scala 2 so we can get away from |
0125b16
to
491a536
Compare
Added some tests based on @eed3si9n's comment. And rebased in the hopes of fixing MIMA failures in travis. |
Ok, I get it now. MIMA complains because some apply and copy methods became private. |
I put the change behind the |
4669e46
to
6e7add6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! Implementation, testing, all 👍.
I think this doesn't need a SIP.
My only concern is that it's a breaking change, but I cannot think of anything that we can do in 2.13 to aid / anticipate migration.
Can this be considered for 2.13.2? |
Under |
Sorry for the delay. I will do my best to look soon. In principle it all looks good. |
Sorry for lagging on this. I've asked Jason to take a look instead. He's been reworking this part of namers. |
@retronym do you intend to try to get this over the finish line for 2.13.2? |
Let's merge this, it's looking good |
Backport from dotty:
private
orprivate[foo]
: the synthesizedcopy
andapply
methods will have the same access modifier.protected
orprotected[foo]
: the synthesizedcopy
method will have the same access modifier. The synthesizedapply
method will remainpublic
, becauseprotected
doesn't make sense in anobject
.Obviously, if a user defines a custom
copy
orapply
method, that one—including its access modifier—will take precedence.See the accompanying pos and neg tests.
Only enabled under
-Xsource:2.14
and by extension under-Xsource:3
.