From b5a3486131d772e7f2b078deb2dc3a7e8b187272 Mon Sep 17 00:00:00 2001 From: "Natalia.Ukhorskaya" Date: Mon, 12 Nov 2012 15:03:54 +0400 Subject: [PATCH] Back-end: correct indexes of local variables for double and long #KT-3033 Fixed --- .../codegen/ImplementationBodyCodegen.java | 7 +++-- .../checkLocalVariablesTable/someClass.kt | 6 ++++ .../codegen/dataClasses/copy/kt3033.kt | 10 +++++++ .../DataClassCodegenTestGenerated.java | 29 +++++++++++-------- 4 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 compiler/testData/checkLocalVariablesTable/someClass.kt create mode 100644 compiler/testData/codegen/dataClasses/copy/kt3033.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 33f3800c8e4..3fc759e5263 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -688,10 +688,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { iv.getfield(JvmClassName.byType(classAsmType).getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor()); } - int parameterIndex = 0; + int parameterIndex = 1; // localVariable 0 = this for (ValueParameterDescriptor parameterDescriptor : function.getValueParameters()) { - iv.load(parameterIndex + 1, typeMapper.mapType(parameterDescriptor.getType())); - parameterIndex++; + Type type = typeMapper.mapType(parameterDescriptor.getType()); + iv.load(parameterIndex, type); + parameterIndex += type.getSize(); } String constructorJvmDescriptor = typeMapper.mapToCallableMethod(constructor).getSignature().getAsmMethod().getDescriptor(); diff --git a/compiler/testData/checkLocalVariablesTable/someClass.kt b/compiler/testData/checkLocalVariablesTable/someClass.kt new file mode 100644 index 00000000000..2ceb1020493 --- /dev/null +++ b/compiler/testData/checkLocalVariablesTable/someClass.kt @@ -0,0 +1,6 @@ +data class someClass(val a: Double, val b: Double) + +// METHOD : copy(DD)LsomeClass; +// VARIABLE : NAME=this TYPE=LsomeClass; INDEX=0 +// VARIABLE : NAME=a TYPE=D INDEX=1 +// VARIABLE : NAME=b TYPE=D INDEX=3 \ No newline at end of file diff --git a/compiler/testData/codegen/dataClasses/copy/kt3033.kt b/compiler/testData/codegen/dataClasses/copy/kt3033.kt new file mode 100644 index 00000000000..7fc12756d88 --- /dev/null +++ b/compiler/testData/codegen/dataClasses/copy/kt3033.kt @@ -0,0 +1,10 @@ +data class A(val a: Double, val b: Double) + +fun box() : String { + val a = A(1.0, 1.0) + val b = a.copy() + if (b.a == 1.0 && b.b == 1.0) { + return "OK" + } + return "fail" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java index e15cf8f1cf8..4a78022451b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/DataClassCodegenTestGenerated.java @@ -84,8 +84,7 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest @TestMetadata("compiler/testData/codegen/dataClasses/copy") public static class Copy extends AbstractDataClassCodegenTest { public void testAllFilesPresentInCopy() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", - new File("compiler/testData/codegen/dataClasses/copy"), "kt", true); + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.codegen.AbstractDataClassCodegenTest", new File("compiler/testData/codegen/dataClasses/copy"), "kt", true); } @TestMetadata("constructorWithDefaultParam.kt") @@ -93,6 +92,21 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/constructorWithDefaultParam.kt"); } + @TestMetadata("copyInNestedDataClass.kt") + public void testCopyInNestedDataClass() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInNestedDataClass.kt"); + } + + @TestMetadata("copyInObjectNestedDataClass.kt") + public void testCopyInObjectNestedDataClass() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInObjectNestedDataClass.kt"); + } + + @TestMetadata("kt3033.kt") + public void testKt3033() throws Exception { + blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/kt3033.kt"); + } + @TestMetadata("paramWithoutProperty.kt") public void testParamWithoutProperty() throws Exception { blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/paramWithoutProperty.kt"); @@ -112,16 +126,7 @@ public class DataClassCodegenTestGenerated extends AbstractDataClassCodegenTest public void testWithGenericParameter() throws Exception { blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/withGenericParameter.kt"); } - - @TestMetadata("copyInNestedDataClass.kt") - public void testCopyInNestedClasses() throws Exception { - blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInNestedDataClass.kt"); - } - - @TestMetadata("copyInObjectNestedDataClass.kt") - public void testCopyInObjectNestedClasses() throws Exception { - blackBoxFileByFullPath("compiler/testData/codegen/dataClasses/copy/copyInObjectNestedDataClass.kt"); - } + } @TestMetadata("compiler/testData/codegen/dataClasses/equals")