[JVM_IR] Do not use invoke-dynamic for targeting inline-only methods.
Fixes https://youtrack.jetbrains.com/issue/KT-46962
This commit is contained in:
committed by
teamcityserver
parent
5c2753b5d1
commit
886ce055f5
+6
@@ -21217,6 +21217,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericLambdaSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineOnly.kt")
|
||||
public void testInlineOnly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineOnly.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("insideInitBlock.kt")
|
||||
public void testInsideInitBlock() throws Exception {
|
||||
|
||||
+5
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
@@ -82,6 +83,10 @@ internal class LambdaMetafactoryArgumentsBuilder(
|
||||
if (context.irIntrinsics.getIntrinsic(implFun.symbol) != null)
|
||||
return null
|
||||
|
||||
// Don't generate reference to inlineOnly methods as those do not exist at runtime.
|
||||
if (implFun.hasAnnotation(INLINE_ONLY_ANNOTATION_FQ_NAME))
|
||||
return null
|
||||
|
||||
if (implFun is IrConstructor && implFun.visibility.isPrivate) {
|
||||
// Kotlin generates constructor accessors differently from Java.
|
||||
// TODO more precise accessibility check (see SyntheticAccessorLowering::isAccessible)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// JVM_TARGET: 1.8
|
||||
// SAM_CONVERSIONS: INDY
|
||||
// WITH_RUNTIME
|
||||
|
||||
// CHECK_BYTECODE_TEXT
|
||||
// JVM_IR_TEMPLATES
|
||||
// 0 java/lang/invoke/LambdaMetafactory
|
||||
|
||||
fun interface Consumer {
|
||||
fun foo(s: String)
|
||||
}
|
||||
|
||||
fun call(c: Consumer) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
// println is inline only and therefore we cannot use invoke-dynamic to target it.
|
||||
call(::println)
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -21187,6 +21187,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericLambdaSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineOnly.kt")
|
||||
public void testInlineOnly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineOnly.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("insideInitBlock.kt")
|
||||
public void testInsideInitBlock() throws Exception {
|
||||
|
||||
+6
@@ -21217,6 +21217,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericLambdaSignature.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("inlineOnly.kt")
|
||||
public void testInlineOnly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineOnly.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("insideInitBlock.kt")
|
||||
public void testInsideInitBlock() throws Exception {
|
||||
|
||||
+5
@@ -17706,6 +17706,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/genericFunInterfaceWithPrimitive.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineOnly.kt")
|
||||
public void testInlineOnly() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineOnly.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("insideInitBlock.kt")
|
||||
public void testInsideInitBlock() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/invokedynamic/sam/insideInitBlock.kt");
|
||||
|
||||
Reference in New Issue
Block a user