JS: don't emit short circuit operators for boolean and/or
See KT-21004
This commit is contained in:
@@ -2251,6 +2251,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("booleanAndOr.kt")
|
||||
public void testBooleanAndOr() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/evaluationOrder/booleanAndOr.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callArgs.kt")
|
||||
public void testCallArgs() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/expression/evaluationOrder/callArgs.kt");
|
||||
|
||||
+11
-7
@@ -191,14 +191,18 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
// Temporary hack to get '%' for deprecated 'mod' operator
|
||||
Name descriptorName = descriptor.getName().equals(OperatorNameConventions.MOD) ? OperatorNameConventions.REM : descriptor.getName();
|
||||
|
||||
switch (descriptorName.asString()) {
|
||||
case "or":
|
||||
return JsBinaryOperator.BIT_OR;
|
||||
case "and":
|
||||
return JsBinaryOperator.BIT_AND;
|
||||
case "xor":
|
||||
return JsBinaryOperator.BIT_XOR;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
KtToken token = OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(descriptorName);
|
||||
if (token == null) {
|
||||
token = OperatorConventions.BOOLEAN_OPERATIONS.inverse().get(descriptorName);
|
||||
}
|
||||
if (token == null) {
|
||||
assert descriptorName.asString().equals("xor");
|
||||
return JsBinaryOperator.BIT_XOR;
|
||||
}
|
||||
return OperatorTable.getBinaryOperator(token);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// EXPECTED_REACHABLE_NODES: 1135
|
||||
var log = ""
|
||||
|
||||
fun foo(a: Boolean, b: () -> Boolean): Boolean = a or b()
|
||||
|
||||
fun bar(a: Boolean, b: () -> Boolean): Boolean = a and b()
|
||||
|
||||
fun box(): String {
|
||||
if (!foo(true) { log += "1"; false }) return "fail1"
|
||||
if (!foo(true) { log += "2"; true }) return "fail2"
|
||||
if (foo(false) { log += "3"; false }) return "fail3"
|
||||
if (!foo(false) { log += "4"; true }) return "fail4"
|
||||
|
||||
if (bar(true) { log += "5"; false }) return "fail5"
|
||||
if (!bar(true) { log += "6"; true }) return "fail6"
|
||||
if (bar(false) { log += "7"; false }) return "fail7"
|
||||
if (bar(false) { log += "8"; true }) return "fail8"
|
||||
|
||||
if (log != "12345678") return "fail log: $log"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user