Skip to content

Value classes: add support for private[this] parameter #1112

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

Merged

Conversation

VladimirNik
Copy link
Contributor

Allow private[this] parameter in value classes:

class A(x: Int) extends AnyVal
class B(private[this] val x: Int) extends AnyVal

Review by @odersky @DarkDimius

@odersky
Copy link
Contributor

odersky commented Feb 19, 2016

I don't think it will work that way. You'll need to create a public accessor for the private field and have all unboxing operations go through the accessor instead of the field.

@DarkDimius
Copy link
Contributor

I believe that the easiest implementation would be to drop Private | PrivateLocal flags from fields inside value classes just after pickling.

@odersky
Copy link
Contributor

odersky commented Feb 19, 2016

That won't work because you might get accidental overrides. If you drop the
flags you need to mangle the name at the same time. But in any case a
non-private parameter is represented as a private field
and a non-private getter. So you might just add the getter and leave the
field in place.

On Fri, Feb 19, 2016 at 5:40 PM, Dmitry Petrashko [email protected]
wrote:

I believe that the easiest implementation would be to drop Private |
PrivateLocal flags from fields inside value classes just after pickling.


Reply to this email directly or view it on GitHub
#1112 (comment).

Martin Odersky
EPFL

@VladimirNik
Copy link
Contributor Author

Update: tests failed due to neg_valueClasses test (I forgot to update the number of errors in tests.scala). Now it's fixed.

@odersky
Copy link
Contributor

odersky commented Feb 20, 2016

LGTM. That was surprisingly simple. Nice!

DarkDimius added a commit that referenced this pull request Feb 20, 2016
…s-param

Value classes: add support for private[this] parameter
@DarkDimius DarkDimius merged commit 6e535f7 into scala:master Feb 20, 2016
@allanrenucci allanrenucci deleted the value-classes-private-this-param branch December 14, 2017 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants