Properly capture local delegated properties in object constructor

#KT-23117 Fixed
This commit is contained in:
Mikhael Bogdanov
2019-02-05 13:45:35 +01:00
parent 9ab6062295
commit b2606735c5
7 changed files with 48 additions and 3 deletions
@@ -67,6 +67,7 @@ import static org.jetbrains.kotlin.codegen.CodegenUtilKt.isGenericToArray;
import static org.jetbrains.kotlin.codegen.CodegenUtilKt.isNonGenericToArray;
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.getDelegatedLocalVariableMetadata;
import static org.jetbrains.kotlin.codegen.inline.InlineCodegenUtils2Kt.initDefaultSourceMappingIfNeeded;
import static org.jetbrains.kotlin.load.java.JvmAbi.*;
import static org.jetbrains.kotlin.resolve.BindingContext.INDEXED_LVALUE_GET;
@@ -975,7 +976,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ClassDescriptor classDescriptor = ((ConstructorDescriptor) containingDeclaration).getConstructedClass();
if (classDescriptor == ImplementationBodyCodegen.this.descriptor) return;
}
lookupInContext(descriptor);
if (lookupInContext(descriptor)) {
if (isDelegatedLocalVariable(descriptor)) {
VariableDescriptor metadata = getDelegatedLocalVariableMetadata((VariableDescriptor) descriptor, bindingContext);
lookupInContext(metadata);
}
}
}
}
@@ -998,8 +1004,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
private void lookupInContext(@NotNull DeclarationDescriptor toLookup) {
context.lookupInContext(toLookup, StackValue.LOCAL_0, state, true);
private boolean lookupInContext(@NotNull DeclarationDescriptor toLookup) {
return context.lookupInContext(toLookup, StackValue.LOCAL_0, state, true) != null;
}
@Override
@@ -0,0 +1,14 @@
// IGNORE_BACKEND: JS_IR, JVM_IR
//WITH_RUNTIME
import kotlin.properties.Delegates.notNull
fun box(): String {
var bunny by notNull<String>()
val obj = object {
val getBunny = { bunny }
}
bunny = "OK"
return obj.getBunny()
}
@@ -9250,6 +9250,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt19690.kt");
}
@TestMetadata("kt23117.kt")
public void testKt23117() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt23117.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");
@@ -9250,6 +9250,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt19690.kt");
}
@TestMetadata("kt23117.kt")
public void testKt23117() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt23117.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");
@@ -9250,6 +9250,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt19690.kt");
}
@TestMetadata("kt23117.kt")
public void testKt23117() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt23117.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");
@@ -7135,6 +7135,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt19690.kt");
}
@TestMetadata("kt23117.kt")
public void testKt23117() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt23117.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");
@@ -8225,6 +8225,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt19690.kt");
}
@TestMetadata("kt23117.kt")
public void testKt23117() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/kt23117.kt");
}
@TestMetadata("localVal.kt")
public void testLocalVal() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/local/localVal.kt");