KT-37059 Support 'String?.plus(Any?)' in JVM_IR
This commit is contained in:
+6
@@ -91,6 +91,12 @@ class IrIntrinsicMethods(val irBuiltIns: IrBuiltIns, val symbols: JvmSymbols) {
|
||||
"enumValueOf",
|
||||
listOf(KotlinBuiltIns.FQ_NAMES.string.toSafe())
|
||||
) to EnumValueOf,
|
||||
Key(
|
||||
KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME,
|
||||
KotlinBuiltIns.FQ_NAMES.string.toSafe(),
|
||||
"plus",
|
||||
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
|
||||
) to StringPlus,
|
||||
irBuiltIns.eqeqSymbol.toKey()!! to Equals(KtTokens.EQEQ),
|
||||
irBuiltIns.eqeqeqSymbol.toKey()!! to Equals(KtTokens.EQEQEQ),
|
||||
irBuiltIns.ieee754equalsFunByOperandType[irBuiltIns.floatClass]!!.toKey()!! to Ieee754Equals(Type.FLOAT_TYPE),
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
object StringPlus : IntrinsicMethod() {
|
||||
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
): IrIntrinsicFunction =
|
||||
IrIntrinsicFunction.create(expression, signature, context, listOf(AsmTypes.JAVA_STRING_TYPE, AsmTypes.OBJECT_TYPE)) {
|
||||
it.invokestatic(
|
||||
IntrinsicMethods.INTRINSICS_CLASS_NAME,
|
||||
"stringPlus",
|
||||
Type.getMethodDescriptor(AsmTypes.JAVA_STRING_TYPE, AsmTypes.JAVA_STRING_TYPE, AsmTypes.OBJECT_TYPE),
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun splus(s: String?, x: Any?) = s + x
|
||||
|
||||
fun box(): String {
|
||||
val test1 = null + ""
|
||||
if (test1 != "null") throw AssertionError("Fail: $test1")
|
||||
|
||||
val ns: String? = "abc"
|
||||
val test2 = ns + ""
|
||||
if (test2 != "abc") throw AssertionError("Fail: $test2")
|
||||
|
||||
val test3 = splus(null, null)
|
||||
if (test3 != "nullnull") throw AssertionError("Fail: $test3")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -14554,6 +14554,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
+5
@@ -14554,6 +14554,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
+5
@@ -13424,6 +13424,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
+5
@@ -13424,6 +13424,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
Generated
+5
@@ -11624,6 +11624,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
+5
@@ -11689,6 +11689,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullPlusString.kt")
|
||||
public void testNullPlusString() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/nullPlusString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("prefixIncDec.kt")
|
||||
public void testPrefixIncDec() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/intrinsics/prefixIncDec.kt");
|
||||
|
||||
Reference in New Issue
Block a user