5c5367d377
The following updates in the JVM/IR plugin were made: * Lots of refactoring with preparation for K/N support: commonization of transformations. * Improved error handling (checks for visibility constraints, appending message about usage constraints in case of an error). * Explicit requirements for the visibility of atomic properties: to prevent leaking they should be private/internal or be members of private/internal classes. * Fixed visibility of generated properties: volatile properties are always private and atomic updaters have the same visibility as the original atomic property. * Volatile fields are generated from scratch and original atomic properties are removed. * Delegated properties support is fixed (only declaration in the same scope is allowed). * Non-inline atomic extensions are forbidden. * For top-level atomics: only one wrapper class per file (with corresponding visibility) is generated. * Bug fixes. The corresponding tickets: https://github.com/Kotlin/kotlinx-atomicfu/issues/322 KT-60528 Merge-request: KT-MR-10579 Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
53 lines
1.2 KiB
Kotlin
Vendored
53 lines
1.2 KiB
Kotlin
Vendored
import kotlinx.atomicfu.*
|
|
import kotlin.test.*
|
|
|
|
class LambdaTest {
|
|
private val a = atomic(0)
|
|
private val rs = atomic<String>("bbbb")
|
|
|
|
private inline fun <T> inlineLambda(
|
|
arg: T,
|
|
crossinline block: (T) -> Unit
|
|
) = block(arg)
|
|
|
|
fun loopInLambda1(to: Int) = inlineLambda(to) sc@ { arg ->
|
|
a.loop { value ->
|
|
a.compareAndSet(value, arg)
|
|
return@sc
|
|
}
|
|
}
|
|
|
|
fun loopInLambda2(to: Int) = inlineLambda(to) { arg1 ->
|
|
inlineLambda(arg1) sc@ { arg2 ->
|
|
a.loop { value ->
|
|
a.compareAndSet(value, arg2)
|
|
return@sc
|
|
}
|
|
}
|
|
}
|
|
|
|
fun loopInLambda2Ref(to: String) = inlineLambda(to) { arg1 ->
|
|
inlineLambda(arg1) sc@ { arg2 ->
|
|
rs.loop { value ->
|
|
rs.compareAndSet(value, arg2)
|
|
return@sc
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test() {
|
|
loopInLambda1(34)
|
|
assertEquals(34, a.value)
|
|
loopInLambda1(77)
|
|
assertEquals(77, a.value)
|
|
loopInLambda2Ref("bbb")
|
|
assertEquals("bbb", rs.value)
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
val testClass = LambdaTest()
|
|
testClass.test()
|
|
return "OK"
|
|
}
|