Skip to content

Commit 4e2561c

Browse files
committed
Pass annotations and fix transient lazy vals bug
1 parent a1af355 commit 4e2561c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
462462
val containerName = LazyLocalName.fresh(x.name.asTermName)
463463
val containerSymbol = newSymbol(claz, containerName, containerFlags, defn.ObjectType).enteredAfter(this)
464464
containerSymbol.addAnnotation(Annotation(defn.VolatileAnnot)) // private @volatile var _x: AnyRef
465+
containerSymbol.addAnnotations(x.symbol.annotations) // pass annotations from original definition
465466
val stat = x.symbol.isStatic
466467
if stat then
467468
containerSymbol.setFlag(JavaStatic)

tests/run/serialization-new.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,11 @@ x = Paul
224224
y = Paul
225225
x equals y: true, y equals x: true
226226

227+
Calculating a1
227228
1
229+
Calculating a2
228230
2
231+
Calculating a1
229232
1
233+
Calculating a2
230234
2

tests/run/serialization-new.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,14 @@ object Test7 {
468468

469469
// Verify that transient lazy vals don't get serialized
470470
class WithTransient extends Serializable {
471-
@transient lazy val a1 = 1
472-
@transient private lazy val a2 = 2
471+
@transient lazy val a1 = {
472+
println("Calculating a1")
473+
1
474+
}
475+
@transient private lazy val a2 = {
476+
println("Calculating a2")
477+
2
478+
}
473479
@transient object B extends Serializable
474480
@transient private object C extends Serializable
475481

0 commit comments

Comments
 (0)