I discovered a difference between Kotlin/JVM and K...
# kotlin-native
r
I discovered a difference between Kotlin/JVM and Kotlin/Native (on Raspberry Pi) behaviour and I’m not sure if I’m misusing
also()
to swap two values here or if this is bug. Given the following code:
Copy code
fun main(args: Array<String>) {
    var x0 = 25
    var y0 = 26

    var x1 = 27
    var y1 = 28
    
    x0 = y0.also { y0 = x0 }
    x1 = y1.also { y1 = x1 }

    println("x0=$x0, y0=$y0, x1=$x1, y1=$y1")
}
Kotlin/JVM will produce the following output (x0 <-> y0 and x1 <-> y1):
Copy code
x0=26, y0=25, x1=28, y1=27
Whereas Kotlin/Native does the following:
Copy code
x0=25, y0=25, x1=27, y1=27
Any thoughts?
1
l
The inconsistent behavior is interesting, so I'm notifying @olonho , but this is a mind twisting way to swap two variables!
r
it is and I don’t like it. But still thought that the difference would be important to mention
o
we cannot reproduce it on current compiler builds, which version do you use? also please use github issue tracker or https://youtrack.jetbrains.com/issues/KT
r
I’m using 0.4 and will try to create a project reproducing this behaviour. I will then use GitHub if the issue persists.
o
Please try with 0.5
r
I will
t
This problem has been fixed in Kotlin Native 0.5.
👍 1