diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index fd60708a39e..d31f303077e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -1296,10 +1296,6 @@ public class ExpressionCodegen extends KtVisitor impleme int index = myFrameMap.leave(variableDescriptor); - if (isSharedVarType(type)) { - v.aconst(null); - v.store(index, OBJECT_TYPE); - } v.visitLocalVariable(variableDescriptor.getName().asString(), type.getDescriptor(), null, scopeStart, blockEnd, index); return null; }); diff --git a/compiler/testData/codegen/bytecodeText/doNotStoreNullsForCapturedVars.kt b/compiler/testData/codegen/bytecodeText/doNotStoreNullsForCapturedVars.kt new file mode 100644 index 00000000000..88fc147ab04 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/doNotStoreNullsForCapturedVars.kt @@ -0,0 +1,14 @@ +fun runNoInline(block: ()-> Unit): Unit { + block() +} + +fun use(x: Int) {} + +fun test(): Unit { + var x = 0 + runNoInline { + use(x) + } +} + +// 0 ACONST_NULL \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index 79b503dd224..00397e98cc5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -132,6 +132,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest(fileName); } + @TestMetadata("doNotStoreNullsForCapturedVars.kt") + public void testDoNotStoreNullsForCapturedVars() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/doNotStoreNullsForCapturedVars.kt"); + doTest(fileName); + } + @TestMetadata("falseSmartCast.kt") public void testFalseSmartCast() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/falseSmartCast.kt");