Boolean operations in JS-backend DO perform short-circuit


#1

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 (https://github.com/JetBrains/kotlin/blob/1.2-Beta/core/builtins/native/kotlin/Boolean.kt#L31).
In the 1.1 docs that sentence isn’t there.


#2

I checked the produced JS code:

    this.myPrint_fzusl$(1, true) || this.myPrint_fzusl$(2, true);
    this.myPrint_fzusl$(3, false) && this.myPrint_fzusl$(4, false);

I guess if that were | and &, it would yield the expected behaviour.


#3

Hello. It’s definitely a bug. I created KT-21004 on YT. Please, report bugs on YT the next time you find one.