Consider the following example:
class ShortCircuitTest {
@Test
fun test() {
myPrint(1, true) or myPrint(2, true)
myPrint(3, false) and myPrint(4, false)
}
fun myPrint(x: Int, r: Boolean): Boolean {
print(x)
return r
}
}
The JVM backend will print 1234
, while the JS backend prints 13
.
I guess the JS behavior should be different.
I use kotlin-1.2.0-beta-88
.
In that version the doc explicitly states that these functions do not perform short-circuit evaluation (kotlin/Boolean.kt at 1.2-Beta · JetBrains/kotlin · GitHub).
In the 1.1 docs that sentence isn’t there.