-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skipped transformation of the nested atomic field loads (#165)
Fixes #160
- Loading branch information
1 parent
ef6ca9b
commit d96ad35
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
atomicfu/src/commonTest/kotlin/kotlinx/atomicfu/test/NestedAtomicFieldLoads.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package kotlinx.atomicfu.test | ||
|
||
import kotlinx.atomicfu.* | ||
import kotlin.test.* | ||
|
||
class NestedAtomicFieldLoads { | ||
private val a = atomic(0) | ||
private val b = atomic(1) | ||
private val c = atomic(2) | ||
private val ref = atomic(A(B(70))) | ||
|
||
private val flag = atomic(false) | ||
|
||
private val arr = AtomicIntArray(7) | ||
|
||
private fun foo(arg1: Int, arg2: Int, arg3: Int, arg4: Int): Int = arg1 + arg2 + arg3 + arg4 | ||
|
||
private class A(val b: B) | ||
private class B(val n: Int) | ||
|
||
@Test | ||
fun testNestedGetField() { | ||
a.value = b.value + c.value | ||
assertEquals(3, a.value) | ||
a.value = foo(a.value, b.value, c.value, ref.value.b.n) | ||
assertEquals(76, a.value) | ||
} | ||
|
||
@Test | ||
fun testNestedAtomicInvocations() { | ||
flag.value = a.compareAndSet(0, 56) | ||
assertTrue(flag.value) | ||
} | ||
|
||
@Test | ||
fun testArrayNestedLoads() { | ||
arr[5].value = b.value | ||
assertEquals(1, arr[5].value) | ||
arr[0].value = foo(arr[5].value, b.value, c.value, ref.value.b.n) | ||
assertEquals(74, arr[0].value) | ||
} | ||
} |