IR: use parameters for captures in field/instance initializers

val y = 1
    object { val x = y }
  ->
    class XKt$1(`$y`: Int) { val x: Int = `$y` }

Note that `$y` is not stored in a field because it's not used outside
the primary constructor.

One exception is captured inline parameters on the JVM backend, as the
bytecode inliner uses field assignment instructions (setfield) to locate
them; removing the field is thus not possible.
This commit is contained in:
pyos
2021-09-16 13:14:27 +02:00
committed by Alexander Udalov
parent 85c53bc24e
commit e1520c61da
4 changed files with 84 additions and 24 deletions
@@ -0,0 +1,25 @@
@kotlin.Metadata
public final class LocalClassWithCapturedParamsKt$localCaptured$A {
// source: 'localClassWithCapturedParams.kt'
enclosing method LocalClassWithCapturedParamsKt.localCaptured()Ljava/lang/Object;
private final field x: int
private final @org.jetbrains.annotations.NotNull field z: java.lang.String
inner (local) class LocalClassWithCapturedParamsKt$localCaptured$A A
public method <init>(p0: int, @Simple(value="K") @org.jetbrains.annotations.NotNull p1: java.lang.String): void
public final method getX(): int
public final @org.jetbrains.annotations.NotNull method getZ(): java.lang.String
}
@kotlin.Metadata
public final class LocalClassWithCapturedParamsKt {
// source: 'localClassWithCapturedParams.kt'
inner (local) class LocalClassWithCapturedParamsKt$localCaptured$A A
public final static @org.jetbrains.annotations.NotNull method localCaptured(): java.lang.Object
}
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class Simple {
// source: 'localClassWithCapturedParams.kt'
public abstract method value(): java.lang.String
}