diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt index 56da54970f8..54c9269fbaa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt @@ -134,8 +134,7 @@ public open class LazyClassMemberScope( private fun generateDataClassMethods(result: MutableCollection, name: Name) { if (!KotlinBuiltIns.isData(thisDescriptor)) return - val constructor = getPrimaryConstructor() - if (constructor == null) return + val constructor = getPrimaryConstructor() ?: return val primaryConstructorParameters = declarationProvider.getOwnerInfo().getPrimaryConstructorParameters() assert(constructor.getValueParameters().size() == primaryConstructorParameters.size()) { "From descriptor: " + constructor.getValueParameters().size() + " but from PSI: " + primaryConstructorParameters.size() } @@ -150,8 +149,6 @@ public open class LazyClassMemberScope( val 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 } - val property = properties.iterator().next() as PropertyDescriptor ++componentIndex diff --git a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt new file mode 100644 index 00000000000..75cc614787b --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt @@ -0,0 +1,9 @@ +data class A1(val x: Int, val y: String, val x: Int) { + val z = "" +} + +data class A2(val x: Int, val y: String) { + val x = "" +} + +data class A3(val :Int, val : Int) diff --git a/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.txt b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.txt new file mode 100644 index 00000000000..218a8267bdc --- /dev/null +++ b/compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.txt @@ -0,0 +1,41 @@ +package + +kotlin.data() internal final class A1 { + public constructor A1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String, /*2*/ x: kotlin.Int) + internal final val x: kotlin.Int + internal final val x: kotlin.Int + internal final val y: kotlin.String + internal final val z: kotlin.String = "" + internal final /*synthesized*/ fun component1(): kotlin.Int + internal final /*synthesized*/ fun component2(): kotlin.String + internal final /*synthesized*/ fun component3(): kotlin.Int + public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.String = ..., /*2*/ x: kotlin.Int = ...): A1 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +kotlin.data() internal final class A2 { + public constructor A2(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String) + internal final val x: kotlin.Int + internal final val x: kotlin.String = "" + internal final val y: kotlin.String + internal final /*synthesized*/ fun component1(): kotlin.String + internal final /*synthesized*/ fun component2(): kotlin.String + public final /*synthesized*/ fun copy(/*0*/ x: kotlin.Int = ..., /*1*/ y: kotlin.String = ...): A2 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +kotlin.data() internal final class A3 { + public constructor A3(/*0*/ : kotlin.Int, /*1*/ : kotlin.Int) + internal final val : kotlin.Int + internal final val : kotlin.Int + internal final /*synthesized*/ fun component1(): kotlin.Int + internal final /*synthesized*/ fun component2(): kotlin.Int + public final /*synthesized*/ fun copy(/*0*/ : kotlin.Int = ..., /*1*/ : kotlin.Int = ...): A3 + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 18ef31fa22f..6bc2bb70aa9 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -2844,6 +2844,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("repeatedProperties.kt") + public void testRepeatedProperties() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dataClasses/repeatedProperties.kt"); + doTest(fileName); + } + @TestMetadata("secondParamIsVal.kt") public void testSecondParamIsVal() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/dataClasses/secondParamIsVal.kt");