diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmLocalClassPopupLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmLocalClassPopupLowering.kt index afadc083cc6..2dde70473ac 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmLocalClassPopupLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/JvmLocalClassPopupLowering.kt @@ -57,7 +57,7 @@ class JvmLocalClassPopupLowering(context: JvmBackendContext) : LocalClassPopupLo // In case there's no primary constructor, it's unclear which constructor should be the enclosing one, so we select the first. (context as JvmBackendContext).customEnclosingFunction[klass.attributeOwnerId] = - container.primaryConstructor ?: container.declarations.firstIsInstanceOrNull() + container.primaryConstructor ?: container.declarations.firstIsInstanceOrNull() ?: error("Class in a non-static initializer found, but container has no constructors: ${container.render()}") return true diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.kt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.kt new file mode 100644 index 00000000000..c3fea392c49 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.kt @@ -0,0 +1,15 @@ +interface A +interface B + +class E { + val irrelevantField = 1 + + init { + // This test checks that EnclosingMethod (named "outer class" in ASM for some reason) of this lambda class contains + // something sensible. Currently, we use one of the constructors (not important which). + val lambda = {} + } + + constructor(a: A) + constructor(b: B) +} diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.txt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.txt new file mode 100644 index 00000000000..a5418dd25e2 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.txt @@ -0,0 +1,31 @@ +@kotlin.Metadata +public interface A { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' +} + +@kotlin.Metadata +public interface B { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' +} + +@kotlin.Metadata +final class E$lambda$1 { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' + enclosing method E.(LB;)V + public final static field INSTANCE: E$lambda$1 + inner (anonymous) class E$lambda$1 + static method (): void + method (): void + public synthetic bridge method invoke(): java.lang.Object + public final method invoke(): void +} + +@kotlin.Metadata +public final class E { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' + private final field irrelevantField: int + inner (anonymous) class E$lambda$1 + public method (@org.jetbrains.annotations.NotNull p0: A): void + public method (@org.jetbrains.annotations.NotNull p0: B): void + public final method getIrrelevantField(): int +} diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor_ir.txt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor_ir.txt new file mode 100644 index 00000000000..6eacf7131f1 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor_ir.txt @@ -0,0 +1,31 @@ +@kotlin.Metadata +public interface A { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' +} + +@kotlin.Metadata +public interface B { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' +} + +@kotlin.Metadata +final class E$lambda$1 { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' + enclosing method E.(LA;)V + public final static field INSTANCE: E$lambda$1 + inner (anonymous) class E$lambda$1 + static method (): void + method (): void + public synthetic bridge method invoke(): java.lang.Object + public final method invoke(): void +} + +@kotlin.Metadata +public final class E { + // source: 'lambdaInInitBlockNoPrimaryConstructor.kt' + private final field irrelevantField: int + inner (anonymous) class E$lambda$1 + public method (@org.jetbrains.annotations.NotNull p0: A): void + public method (@org.jetbrains.annotations.NotNull p0: B): void + public final method getIrrelevantField(): int +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index 6e1830b912f..23b8c3f7c19 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -469,6 +469,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt"); } + @TestMetadata("lambdaInInitBlockNoPrimaryConstructor.kt") + public void testLambdaInInitBlockNoPrimaryConstructor() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.kt"); + } + @TestMetadata("transformedConstructor.kt") public void testTransformedConstructor() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/transformedConstructor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index ba578531e6d..0cc5ec43a0c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -439,6 +439,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt"); } + @TestMetadata("lambdaInInitBlockNoPrimaryConstructor.kt") + public void testLambdaInInitBlockNoPrimaryConstructor() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/lambdaInInitBlockNoPrimaryConstructor.kt"); + } + @TestMetadata("transformedConstructor.kt") public void testTransformedConstructor() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/transformedConstructor.kt");