Do not apply constant folding for non built-in functions
#KT-15872 Fixed
This commit is contained in:
+2
@@ -449,6 +449,8 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
private fun evaluateCall(callExpression: KtExpression, receiverExpression: KtExpression, expectedType: KotlinType?): CompileTimeConstant<*>? {
|
||||
val resolvedCall = callExpression.getResolvedCall(trace.bindingContext) ?: return null
|
||||
|
||||
if (!KotlinBuiltIns.isBuiltIn(resolvedCall.resultingDescriptor)) return null
|
||||
|
||||
val resultingDescriptorName = resolvedCall.resultingDescriptor.name
|
||||
|
||||
val argumentForReceiver = createOperationArgumentForReceiver(resolvedCall, receiverExpression) ?: return null
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
infix fun Int.rem(other: Int) = 10
|
||||
infix operator fun Int.minus(other: Int): Int = 20
|
||||
|
||||
fun box(): String {
|
||||
val a = 5 rem 2
|
||||
if (a != 10) return "fail 1"
|
||||
|
||||
val b = 5 minus 3
|
||||
if (b != 20) return "fail 2"
|
||||
|
||||
val a1 = 5.rem(2)
|
||||
if (a1 != 1) return "fail 3"
|
||||
|
||||
val b2 = 5.minus(3)
|
||||
if (b2 != 2) return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
@kotlin.Metadata
|
||||
public final class InfixFunctionOverBuiltinMemberKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method minus(p0: int, p1: int): int
|
||||
public final static method rem(p0: int, p1: int): int
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE, -UNUSED_PARAMETER
|
||||
|
||||
infix fun Int.rem(other: Int) = 10
|
||||
infix operator fun Int.minus(other: Int): Int = 20
|
||||
|
||||
const val a1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>(-5) rem 2<!>
|
||||
const val a2 = (-5).rem(2)
|
||||
|
||||
const val b1 = <!CONST_VAL_WITH_NON_CONST_INITIALIZER!>5 minus 3<!>
|
||||
const val b2 = 5.minus(3)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
public const val a1: kotlin.Int
|
||||
public const val a2: kotlin.Int = -1
|
||||
public const val b1: kotlin.Int
|
||||
public const val b2: kotlin.Int = 2
|
||||
public operator infix fun kotlin.Int.minus(/*0*/ other: kotlin.Int): kotlin.Int
|
||||
public infix fun kotlin.Int.rem(/*0*/ other: kotlin.Int): kotlin.Int
|
||||
+6
@@ -11141,6 +11141,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infixFunctionOverBuiltinMember.kt")
|
||||
public void testInfixFunctionOverBuiltinMember() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/infixFunctionOverBuiltinMember.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt14201.kt")
|
||||
public void testKt14201() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt");
|
||||
|
||||
@@ -7378,6 +7378,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infixFunOverBuiltinMemberInConst.kt")
|
||||
public void testInfixFunOverBuiltinMemberInConst() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/evaluate/infixFunOverBuiltinMemberInConst.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("intOverflow.kt")
|
||||
public void testIntOverflow() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/evaluate/intOverflow.kt");
|
||||
|
||||
@@ -11141,6 +11141,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infixFunctionOverBuiltinMember.kt")
|
||||
public void testInfixFunctionOverBuiltinMember() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/infixFunctionOverBuiltinMember.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt14201.kt")
|
||||
public void testKt14201() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt");
|
||||
|
||||
@@ -12888,6 +12888,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("infixFunctionOverBuiltinMember.kt")
|
||||
public void testInfixFunctionOverBuiltinMember() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/infixFunctionOverBuiltinMember.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt14201.kt")
|
||||
public void testKt14201() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt");
|
||||
|
||||
Reference in New Issue
Block a user