JVM IR: fix enclosing constructor for lambdas in inner classes
Before this change, we stored the enclosing constructor in a map in JvmBackendContext before moving lambdas and local classes out of initializer blocks. However, in case the lambda was declared in an inner class, we stored a reference to the unlowered constructor of the inner class, whose JVM signature is "()V" instead of the correct "(LOuter;)V". Java reflection then threw exception if we tried to call `getEnclosingConstructor()` on such class at runtime. Proguard finished with errors for the same reason. It turns out that we can just store the fact that the class has been moved, and load the matching constructor in codegen, where everything is already lowered and guaranteed to match with the signatures of the actual generated declarations. #KT-41668 Fixed
This commit is contained in:
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
class Outer {
|
||||
inner class Inner {
|
||||
// This test checks the EnclosingMethod attribute of this lambda class.
|
||||
val lambda = {}
|
||||
}
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
@kotlin.Metadata
|
||||
final class Outer$Inner$lambda$1 {
|
||||
// source: 'lambdaInInnerClassConstructor.kt'
|
||||
enclosing method Outer$Inner.<init>(LOuter;)V
|
||||
public final static field INSTANCE: Outer$Inner$lambda$1
|
||||
inner (anonymous) class Outer$Inner$lambda$1
|
||||
static method <clinit>(): void
|
||||
method <init>(): void
|
||||
public synthetic bridge method invoke(): java.lang.Object
|
||||
public final method invoke(): void
|
||||
public final inner class Outer$Inner
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class Outer$Inner {
|
||||
// source: 'lambdaInInnerClassConstructor.kt'
|
||||
private final @org.jetbrains.annotations.NotNull field lambda: kotlin.jvm.functions.Function0
|
||||
synthetic final field this$0: Outer
|
||||
inner (anonymous) class Outer$Inner$lambda$1
|
||||
public method <init>(p0: Outer): void
|
||||
public final @org.jetbrains.annotations.NotNull method getLambda(): kotlin.jvm.functions.Function0
|
||||
public final inner class Outer$Inner
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class Outer {
|
||||
// source: 'lambdaInInnerClassConstructor.kt'
|
||||
public method <init>(): void
|
||||
public final inner class Outer$Inner
|
||||
}
|
||||
Reference in New Issue
Block a user