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

private[this] var in class constructor disallows mutation #6165

Closed
scabug opened this issue Aug 1, 2012 · 6 comments
Closed

private[this] var in class constructor disallows mutation #6165

scabug opened this issue Aug 1, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented Aug 1, 2012

scala> class PT(private[this] var f:String) { f = f + "hellO"; def ff = f }
defined class PT

scala> (new PT("")).ff
res0: String = ""

scala> class P(private var f:String) { f = f + "hellO"; def ff = f }
defined class P

scala> (new P("")).ff
res1: String = hellO

Is this intentional?

@scabug
Copy link
Author

scabug commented Aug 1, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6165?orig=1
Reporter: Artūras Šlajus (arturaz)
Affected Versions: 2.9.2
Duplicates #6880

@scabug
Copy link
Author

scabug commented Aug 1, 2012

Artūras Šlajus (arturaz) said:
From #scala @ freenode.

! class P(private[this] var f:String) { f = f + "hellO"; def ff = f }
<multibot_> defined class P
! new P("").ff
<multibot_> String = ""
! class P(private var f:String) { f = f + "hellO"; def ff = f }
<multibot_> defined class P
! new P("").ff
<multibot_> String = hellO
definitely a bug...
oh, wow, I've discovered a scala bug? :]
! class P(protected var f:String) { f = f + "hellO"; def ff = f }; new P("").ff
<multibot_> defined class P
<multibot_> String = hellO
arturaz: have a cookie :)

@scabug
Copy link
Author

scabug commented Aug 1, 2012

@paulp said:
It only loses the change when issued from the constructor. If you add

def g { f = f + "hellO" }

And call g, it works.

@SethTisue
Copy link
Member

still present in 2.12.4

@som-snytt
Copy link

Fixed in 2.13, but I didn't see where.

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0 Nov 24, 2019
@som-snytt
Copy link

I didn't see that it duplicates #6880

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

3 participants