From c9ad290ad544c2b9c29b5bb06bf6f799e4469401 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 26 Jul 2017 17:31:58 +0300 Subject: [PATCH] Do not store null for temporary in destructuring assignment #KT-19256 Fixed Target versions 1.1.5 --- .../src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java | 4 ---- .../bytecodeText/doNotStoreNullForTmpInDestructuring.kt | 5 +++++ .../jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/doNotStoreNullForTmpInDestructuring.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index ab2b0515803..9f766cc5a22 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -3457,10 +3457,6 @@ public class ExpressionCodegen extends KtVisitor impleme initializeDestructuringDeclarationVariables(multiDeclaration, initializerAsReceiver, local, asProperty); - if (initializerAsmType.getSort() == Type.OBJECT || initializerAsmType.getSort() == Type.ARRAY) { - v.aconst(null); - v.store(tempVarIndex, initializerAsmType); - } myFrameMap.leaveTemp(initializerAsmType); return StackValue.none(); diff --git a/compiler/testData/codegen/bytecodeText/doNotStoreNullForTmpInDestructuring.kt b/compiler/testData/codegen/bytecodeText/doNotStoreNullForTmpInDestructuring.kt new file mode 100644 index 00000000000..0976851b5b1 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/doNotStoreNullForTmpInDestructuring.kt @@ -0,0 +1,5 @@ +fun test(p: Pair) { + val (x, y) = p +} + +// 0 ACONST_NULL diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index c37a8d1df9c..9e7f364a4cd 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("doNotStoreNullForTmpInDestructuring.kt") + public void testDoNotStoreNullForTmpInDestructuring() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/doNotStoreNullForTmpInDestructuring.kt"); + doTest(fileName); + } + @TestMetadata("doNotStoreNullsForCapturedVars.kt") public void testDoNotStoreNullsForCapturedVars() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/doNotStoreNullsForCapturedVars.kt");