Kotlin / kotlinx-atomicfu

The idiomatic way to use atomic operations in Kotlin
Other
926 stars 59 forks source link

::<init>: Unsupported operation on atomic variable #461

Closed Junzz0 closed 3 months ago

Junzz0 commented 4 months ago
private val _beanTemperature = atomic(Float.NaN)
override val beanTemperature: Float by _beanTemperature

atomicfu will compile incorrectly on the desktop, but it will compile successfully on Android.

Junzz0 commented 4 months ago

Kotlin : 2.0.0 kotlinx-atomicfu : 0.25.0 kotlinx-atomicfu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "kotlinxAtomicfu" } kotlinx-atomicfu = { id = "org.jetbrains.kotlinx.atomicfu", version.ref = "kotlinxAtomicfu" }

Junzz0 commented 3 months ago

kotlin-atomicfu = { id = "org.jetbrains.kotlin.plugin.atomicfu", version.ref = "kotlin" }

The compilation was successful with this plugin.

mvicsokolova commented 3 months ago

Hi! If you apply the gradle plugin:

plugins {
     id("org.jetbrains.kotlinx.atomicfu") version "0.25.0"
}

And enable compiler plugin transformations by setting this flag in your gradle.properties: kotlinx.atomicfu.enableJvmIrTransformation=true, this code should be compiled successfully.

(org.jetbrains.kotlin.plugin.atomicfu is not supposed to be applied directly -- using the gradle plugin org.jetbrains.kotlinx.atomicfu + JVM IR transformation flag is the correct way).

Junzz0 commented 3 months ago

Thanks, it was successfully compiled after the modification.πŸ‘πŸΌπŸ‘πŸΌ