Skip to content

releaseFence needs to be added at the end of constructors of classes that contain mixin fields #9424

Closed
@smarter

Description

@smarter

Since #8652, fields in classes coming from traits are no longer marked final because they're set outside of the class constructor. When this was changed in scalac, they also had to add calls to releaseFence at the end of these constructors, this is justified with a comment:

              // If the field is mutable, it won't be final, so we can write to it in a setter.
              // If it's not, we still need to initialize it, and make sure it's safely published.
              // Since initialization is performed (lexically) outside of the constructor (in the trait setter),
              // we have to make the field mutable starting with classfile format 53
              // (it was never allowed, but the verifier enforces this now).

from scala/scala#7028, which we should port.

Tentatively assigning to @sjrd since unfortunately for him he has become our resident mixin expert :).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions