[JS Legacy] Add an implicit cast to int for the mod operation
^KT-45620 Fixed
This commit is contained in:
committed by
Space
parent
34ca38d1a0
commit
68117faa73
@@ -7746,6 +7746,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/number/intIncDecOverflow.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intMod.kt")
|
||||
public void testIntMod() throws Exception {
|
||||
runTest("js/js.translator/testData/box/number/intMod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intOverflow.kt")
|
||||
public void testIntOverflow() throws Exception {
|
||||
|
||||
+12
@@ -83,6 +83,14 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
}
|
||||
};
|
||||
|
||||
private static final BinaryOperationIntrinsicBase NUMBER_REM_INTRINSIC = new BinaryOperationIntrinsicBase() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression doApply(@NotNull JsExpression left, @NotNull JsExpression right, @NotNull TranslationContext context) {
|
||||
return JsAstUtils.toInt32(JsAstUtils.mod(left, right));
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
private static final BinaryOperationIntrinsicBase BUILTINS_COMPARE_TO_INTRINSIC = new BinaryOperationIntrinsicBase() {
|
||||
@NotNull
|
||||
@@ -120,6 +128,7 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
private static final DescriptorPredicate BOOLEAN_OPERATIONS = pattern("Boolean.or|and|xor");
|
||||
private static final DescriptorPredicate STRING_PLUS = pattern("String.plus");
|
||||
private static final DescriptorPredicate INT_MULTIPLICATION = pattern("Int.times(Int)");
|
||||
private static final DescriptorPredicate NUMBER_REM = pattern("Byte|Short|Int.rem(Byte|Short|Int)");
|
||||
|
||||
private static final DescriptorPredicate CHAR_RANGE_TO = pattern("Char.rangeTo(Char)");
|
||||
private static final DescriptorPredicate NUMBER_RANGE_TO = pattern("Byte|Short|Int.rangeTo(Byte|Short|Int)");
|
||||
@@ -161,6 +170,9 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
if (INT_MULTIPLICATION.test(descriptor)) {
|
||||
return INT_MULTIPLICATION_INTRINSIC;
|
||||
}
|
||||
if (NUMBER_REM.test(descriptor)) {
|
||||
return NUMBER_REM_INTRINSIC;
|
||||
}
|
||||
if (NUMBER_RANGE_TO.test(descriptor)) {
|
||||
return new RangeToIntrinsic(descriptor);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
fun testModNegativeInt() {
|
||||
// wrapper prevents the constants folding
|
||||
infix fun Int.myModInt(y: Int): Any = this % y
|
||||
|
||||
Reference in New Issue
Block a user