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

Delegated properties should be read-only #463

Open
mvicsokolova opened this issue Aug 1, 2024 · 0 comments
Open

Delegated properties should be read-only #463

mvicsokolova opened this issue Aug 1, 2024 · 0 comments
Assignees
Labels
compiler-plugin Issues related to the atomicfu-compiler-plugin deprecation A feature that is going to deprecated and removed in future releases

Comments

@mvicsokolova
Copy link
Collaborator

mvicsokolova commented Aug 1, 2024

Currently, to expose the value of an atomic property to the public, one can declare a delegated property like this:

private val _a = atomic(0)
public var a: Int by _a

⚠️It's allowed to declare a delegated var, though it may e.g. be misused for an incorrect increment:

a++ // This is not an atomic increment !

Suggestion

To prevent erroneous usages, I suggest allowing only read-only delegated properties:

private val _a = atomic(0)
public val a: Int by _a // This property should be read-only

Additionally, delegation to atomic factory should be deprecated too, in favor for declaration of @volatile property

@mvicsokolova mvicsokolova added deprecation A feature that is going to deprecated and removed in future releases compiler-plugin Issues related to the atomicfu-compiler-plugin labels Aug 1, 2024
@mvicsokolova mvicsokolova self-assigned this Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-plugin Issues related to the atomicfu-compiler-plugin deprecation A feature that is going to deprecated and removed in future releases
Projects
None yet
Development

No branches or pull requests

1 participant