diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index ebae72eb131..8e93f4e0a55 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -848,7 +848,11 @@ public class AsmUtil { @NotNull ClassBuilder v ) { String outerClassName = getOuterClassName(descriptor, originalDescriptor, typeMapper); + FunctionDescriptor function = DescriptorUtils.getParentOfType(descriptor, FunctionDescriptor.class); + while (function != null && JvmCodegenUtil.isLambdaWhichWillBeInlined(typeMapper.getBindingContext(), function)) { + function = DescriptorUtils.getParentOfType(function, FunctionDescriptor.class); + } if (function != null) { Method method = typeMapper.mapSignature(function).getAsmMethod(); diff --git a/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/kt6368.kt b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/kt6368.kt new file mode 100644 index 00000000000..92ed2f45efe --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/reflection/enclosing/kt6368.kt @@ -0,0 +1,24 @@ +import kotlin.properties.Delegates +import java.util.HashMap + +trait R { + fun result(): String +} + +val a by Delegates.lazy { + with(HashMap()) { + put("result", object : R { + override fun result(): String = "OK" + }) + this + } +} + +fun box(): String { + val r = a["result"] + + // Check that reflection won't fail + r.javaClass.getEnclosingMethod().toString() + + return r.result() +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 973672450b5..9cce3b2d4c4 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -2451,6 +2451,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/reflection/enclosing"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("kt6368.kt") + public void testKt6368() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/kt6368.kt"); + doTestWithStdlib(fileName); + } + @TestMetadata("localClassInTopLevelFunction.kt") public void testLocalClassInTopLevelFunction() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/localClassInTopLevelFunction.kt");