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

annotations not applied to private[this] fields in traits #8087

Closed
scabug opened this issue Dec 16, 2013 · 6 comments
Closed

annotations not applied to private[this] fields in traits #8087

scabug opened this issue Dec 16, 2013 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Dec 16, 2013

Annotations like @transient and @volatile are not correctly applied to private[this] fields inside traits. This can easily lead to incorrect behavior (I was surprised to find my program broke when I changed a @transient var in a trait from private to private[this].)

trait Foo {
  @transient private[this] var a: String = "" // not transient!!
  @transient private var b: String = ""
  @transient var c: String = ""
  
  @transient private[this] val d: String = "" // not transient!!
  @transient private val e: String = ""
  @transient val f: String = ""

  @volatile private[this] var x: String = ""  // not volatile!! 
  @volatile private var y: String = ""
  @volatile var z: String = ""
}

class Bar extends Foo
@scabug
Copy link
Author

scabug commented Dec 16, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8087?orig=1
Reporter: Jeff Olson (jdolson)
Affected Versions: 2.10.3
See #7954

@scabug
Copy link
Author

scabug commented Dec 16, 2013

Jeff Olson (jdolson) said:
If the fix is non-trivial, it would at least be nice to have a warning that your annotation will get ignored in such cases with the suggestion to change the field from private[this] to private.

@scabug
Copy link
Author

scabug commented Dec 16, 2013

@gkossakowski said:
This is indeed bad. I'll make this critical issue for 2.11 so we make sure it's fixed before RC1.

@scabug
Copy link
Author

scabug commented Dec 16, 2013

@retronym said:
See also #7954, in which the @Strictfp annotations is dropped on the floor as code is moved around in our encoding of traits and value classes.

@scabug
Copy link
Author

scabug commented Dec 16, 2013

Jeff Olson (jdolson) said:
What makes this extra fun, is that the workaround of replacing private[this] with private may not do any good. This is because sbt won't necessarily recompile classes implementing the trait because it doesn't think the public interface of the trait has changed.

So be sure and do a clean compile if you apply this workaround.

@scabug scabug closed this as completed Oct 1, 2014
@scabug
Copy link
Author

scabug commented Oct 1, 2014

@retronym said:
Fixed for 2.11.3: scala/scala#4010

@scabug scabug added this to the 2.11.3 milestone Apr 7, 2017
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

2 participants