Generate sam wrappers in inlined lambda in same way as in inline function
#KT-24825 Fixed
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.kotlin.codegen.context.CodegenContext
|
||||
import org.jetbrains.kotlin.codegen.context.InlineLambdaContext
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -35,9 +36,19 @@ class SamWrapperClasses(private val state: GenerationState) {
|
||||
expressionCodegen: ExpressionCodegen,
|
||||
contextDescriptor: CallableMemberDescriptor
|
||||
): Type {
|
||||
val isInsideInline = InlineUtil.isInlineOrContainingInline(expressionCodegen.context.contextDescriptor)
|
||||
val isInsideInline = InlineUtil.isInlineOrContainingInline(expressionCodegen.context.contextDescriptor) ||
|
||||
isInsideInlineLambdaContext(expressionCodegen.context, state)
|
||||
return samInterfaceToWrapperClass.getOrPut(WrapperKey(samType, file, isInsideInline)) {
|
||||
SamWrapperCodegen(state, samType, expressionCodegen.parentCodegen, isInsideInline).genWrapper(file, contextDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isInsideInlineLambdaContext(context: CodegenContext<*>, state: GenerationState):Boolean {
|
||||
var parent: CodegenContext<*>? = context
|
||||
while (parent != null && parent != state.rootContext) {
|
||||
if (parent is InlineLambdaContext) return true
|
||||
parent = parent.parentContext
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
|
||||
// FILE: JavaClass.java
|
||||
public class JavaClass {
|
||||
public static void run(Runnable l) {
|
||||
l.run();
|
||||
}
|
||||
|
||||
public static void s(Runnable a, Runnable onError) {
|
||||
a.run();
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
var state = ""
|
||||
|
||||
fun unit() {}
|
||||
|
||||
class B {
|
||||
val s = mutableListOf<Unit>()
|
||||
|
||||
init {
|
||||
s.add(JavaClass.s({ state += "O" }, ::unit))
|
||||
|
||||
Any().apply {
|
||||
JavaClass.run {
|
||||
s.add(JavaClass.s({ state += "K" }, ::unit))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
B()
|
||||
return state
|
||||
}
|
||||
Generated
+5
@@ -19390,6 +19390,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt24825.kt")
|
||||
public void testKt24825() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/kt24825.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("partialSam.kt")
|
||||
public void testPartialSam() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
|
||||
|
||||
+5
@@ -19390,6 +19390,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt24825.kt")
|
||||
public void testKt24825() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/kt24825.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("partialSam.kt")
|
||||
public void testPartialSam() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
|
||||
|
||||
+5
@@ -19390,6 +19390,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/sam/kt22906_2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt24825.kt")
|
||||
public void testKt24825() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/kt24825.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("partialSam.kt")
|
||||
public void testPartialSam() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/sam/partialSam.kt");
|
||||
|
||||
Reference in New Issue
Block a user