-
Notifications
You must be signed in to change notification settings - Fork 1.1k
@transient lazy val does not get marked as ACC_TRANSIENT #15149
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
There is a test for this in https://github.com/lampepfl/dotty/blob/7c446ce8b2bf7031a6cf223b5f6a2782c1543016/tests/run/serialization-new.scala#L469-L495 but from what I can tell it actually doesn't verify that the lazy vals aren't serialized. |
It seems that
In the SIP it's the |
It seems that the fields are serialized in the test as well. After modifying the test to this: @transient lazy val a1 = {
println("Recalculating a1")
1
}
@transient private lazy val a2 = {
println("Recalculating a2")
2
} The output is:
So the fields are not recalculated, they are deserialized. |
Ok so it seems that in the import java.lang.Deprecated
class Test() {
@Deprecated @volatile @transient lazy val lazyVal = "lazy"
@Deprecated @volatile @transient lazy val lazyVal2 = "lazy"
@Deprecated @volatile @transient val ordinaryVal = "ordinary"
} Compiles to:
It seems that it's not addressed in the rework in #14545, but I may be missing something so I'd like to tag @olsdavis as he is the author of most commits in this PR. If that's the case, then my suggestions are:
That should cover the transient case. However, volatile is a separate issue as it should probably also affect the bitmap - maybe we should introduce another bitmap or make all bitmaps volatile by default? |
The problem is still present in 3.2.0. Any idea when this might get fixed? |
It's going to be fixed in: |
Compiler version
3.1.0 and 3.1.1
Minimized code
Output
javap generates:-
Expectation
0bitmap$1 and lazyVal$lzy1 should both have flag ACC_TRANSIENT.
I am also confused when reading SIP-20 (version 6) as to what OFFSET$0 does - it does not appear in https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals-init.html equivalent code (how could it, an ACC_STATIC can not be directly be directly created in Scala). But it does appear in the code produced by 3.1.0 and 3.1.1. Being ACC_STATIC it can not also be ACC_TRANSIENT, but I am unsure whether the code as currently implemented would survive serialisation or any equivalent code following the same rules for what get processed.
The text was updated successfully, but these errors were encountered: