diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 50e0405f361..1baf3b45dc6 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -806,7 +806,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { FunctionCodegen.endVisit(mv, "toString", myClass); } - private Type genPropertyOnStack(InstructionAdapter iv, MethodContext context, PropertyDescriptor propertyDescriptor, int index) { + private Type genPropertyOnStack(InstructionAdapter iv, MethodContext context, @NotNull PropertyDescriptor propertyDescriptor, int index) { iv.load(index, classAsmType); if (couldUseDirectAccessToProperty(propertyDescriptor, /* forGetter = */ true, /* isDelegated = */ false, context)) { Type type = typeMapper.mapType(propertyDescriptor.getType()); @@ -839,6 +839,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (!componentType.equals(Type.VOID_TYPE)) { PropertyDescriptor property = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, descriptorToDeclaration(parameter)); + assert property != null : "Property descriptor is not found for primary constructor parameter: " + parameter; + genPropertyOnStack(iv, context, property, 0); } iv.areturn(componentType); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassMemberScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassMemberScope.java index 4be6e8466c9..601de91be18 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassMemberScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyClassMemberScope.java @@ -157,19 +157,26 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope primaryConstructorParameters = declarationProvider.getOwnerInfo().getPrimaryConstructorParameters(); + assert constructor.getValueParameters().size() == primaryConstructorParameters.size() + : "From descriptor: " + constructor.getValueParameters().size() + " but from PSI: " + primaryConstructorParameters.size(); + + int componentIndex = 0; for (ValueParameterDescriptor parameter : constructor.getValueParameters()) { if (parameter.getType().isError()) continue; + if (!primaryConstructorParameters.get(parameter.getIndex()).hasValOrVarNode()) continue; + Set properties = getProperties(parameter.getName()); if (properties.isEmpty()) continue; assert properties.size() == 1 : "A constructor parameter is resolved to more than one (" + properties.size() + ") property: " + parameter; PropertyDescriptor property = (PropertyDescriptor) properties.iterator().next(); if (property == null) continue; - ++parameterIndex; - if (name.equals(Name.identifier(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX + parameterIndex))) { + ++componentIndex; + + if (name.equals(Name.identifier(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX + componentIndex))) { SimpleFunctionDescriptor functionDescriptor = - DescriptorResolver.createComponentFunctionDescriptor(parameterIndex, property, + DescriptorResolver.createComponentFunctionDescriptor(componentIndex, property, parameter, thisDescriptor, trace); result.add(functionDescriptor); break; diff --git a/compiler/testData/diagnostics/tests/dataClasses/paramNameSameToField.kt b/compiler/testData/diagnostics/tests/dataClasses/paramNameSameToField.kt new file mode 100644 index 00000000000..d95b6a261b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/paramNameSameToField.kt @@ -0,0 +1,10 @@ +data class A(foo: String, val bar: Int, other: Long) { + val foo = foo + val other = other +} + +fun test(a: A) { + a.component1() + a.component2() + a.component3() +} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt b/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt new file mode 100644 index 00000000000..ba25eadce92 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt @@ -0,0 +1,7 @@ +//ALLOW_AST_ACCESS +package test + +data class A(foo: String, val bar: Int, other: Long) { + val foo = foo + val other = other +} \ No newline at end of file diff --git a/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.txt b/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.txt new file mode 100644 index 00000000000..2b3250149b7 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.txt @@ -0,0 +1,13 @@ +package test + +kotlin.data() internal final class A { + /*primary*/ public constructor A(/*0*/ foo: kotlin.String, /*1*/ bar: kotlin.Int, /*2*/ other: kotlin.Long) + internal final val bar: kotlin.Int + internal final fun (): kotlin.Int + internal final val foo: kotlin.String + internal final fun (): kotlin.String + internal final val other: kotlin.Long + internal final fun (): kotlin.Long + internal final /*synthesized*/ fun component1(): kotlin.Int + internal final /*synthesized*/ fun copy(/*0*/ foo: kotlin.String, /*1*/ bar: kotlin.Int = ..., /*2*/ other: kotlin.Long): test.A +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index c58717676ea..3b9e1d4c358 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2151,6 +2151,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("paramNameSameToField.kt") + public void testParamNameSameToField() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dataClasses/paramNameSameToField.kt"); + doTest(fileName); + } + @TestMetadata("secondParamIsVal.kt") public void testSecondParamIsVal() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dataClasses/secondParamIsVal.kt"); diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java index e0b7495741d..24c0c86e528 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadJavaTestGenerated.java @@ -2717,6 +2717,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { doTestCompiledKotlin(fileName); } + @TestMetadata("ParamNameSameToField.kt") + public void testParamNameSameToField() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt"); + doTestCompiledKotlin(fileName); + } + @TestMetadata("TwoVals.kt") public void testTwoVals() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt"); diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveRecursiveComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveRecursiveComparingTestGenerated.java index 06f64483e0b..2b3ba996043 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveRecursiveComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveRecursiveComparingTestGenerated.java @@ -959,6 +959,12 @@ public class LazyResolveRecursiveComparingTestGenerated extends AbstractLazyReso doTest(fileName); } + @TestMetadata("ParamNameSameToField.kt") + public void testParamNameSameToField() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt"); + doTest(fileName); + } + @TestMetadata("TwoVals.kt") public void testTwoVals() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt"); diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/LazyResolveByStubTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/stubs/LazyResolveByStubTestGenerated.java index 5980735abde..bda75b6ff85 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/LazyResolveByStubTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/LazyResolveByStubTestGenerated.java @@ -956,6 +956,12 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes doTest(fileName); } + @TestMetadata("ParamNameSameToField.kt") + public void testParamNameSameToField() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/ParamNameSameToField.kt"); + doTest(fileName); + } + @TestMetadata("TwoVals.kt") public void testTwoVals() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/dataClass/TwoVals.kt");