From dcd29cb65d21f11a0c0bec3a7499be3fbbe9e70c Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 12 Mar 2015 14:18:22 +0300 Subject: [PATCH] Revert "Generate descriptor for trait constructor. Exception is thrown otherwise (EA-38416)" This reverts commit 6ba120bba8efbfac97c46bb6c27ccf0589adc1af. --- .../lazy/descriptors/LazyClassMemberScope.kt | 43 ++++++++-------- .../diagnostics/tests/TraitWithConstructor.kt | 7 --- .../tests/TraitWithConstructor.txt | 30 ----------- compiler/testData/psi/TraitConstructor.kt | 2 - compiler/testData/psi/TraitConstructor.txt | 50 ------------------- .../checkers/JetDiagnosticsTestGenerated.java | 6 --- .../parsing/JetParsingTestGenerated.java | 6 --- 7 files changed, 23 insertions(+), 121 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/TraitWithConstructor.kt delete mode 100644 compiler/testData/diagnostics/tests/TraitWithConstructor.txt delete mode 100644 compiler/testData/psi/TraitConstructor.kt delete mode 100644 compiler/testData/psi/TraitConstructor.txt 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 b42221e68b9..5496cbdfc8d 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 @@ -274,28 +274,25 @@ public open class LazyClassMemberScope( public fun getPrimaryConstructor(): ConstructorDescriptor? = primaryConstructor() protected open fun resolvePrimaryConstructor(): ConstructorDescriptor? { - val ownerInfo = declarationProvider.getOwnerInfo() - val classOrObject = ownerInfo.getCorrespondingClassOrObject() - if (!thisDescriptor.getKind().isSingleton() && !classOrObject.isObjectLiteral()) { - assert(classOrObject is JetClass) { "No JetClass for $thisDescriptor" } - classOrObject as JetClass - - if (DescriptorUtils.isTrait(thisDescriptor) && declarationProvider.getOwnerInfo().getPrimaryConstructorParameters().isEmpty()) { - return null + if (GENERATE_CONSTRUCTORS_FOR.contains(thisDescriptor.getKind())) { + val ownerInfo = declarationProvider.getOwnerInfo() + val classOrObject = ownerInfo.getCorrespondingClassOrObject() + if (!thisDescriptor.getKind().isSingleton() && !classOrObject.isObjectLiteral()) { + assert(classOrObject is JetClass) { "No JetClass for $thisDescriptor" } + classOrObject as JetClass + val constructor = c.descriptorResolver.resolvePrimaryConstructorDescriptor( + thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace) + constructor ?: return null + setDeferredReturnType(constructor) + return constructor + } + else { + val constructor = DescriptorResolver.createAndRecordPrimaryConstructorForObject(classOrObject, thisDescriptor, trace) + setDeferredReturnType(constructor) + return constructor } - - val constructor = c.descriptorResolver.resolvePrimaryConstructorDescriptor( - thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace) - - assert(constructor != null) { "No constructor created for $thisDescriptor" } - setDeferredReturnType(constructor) - return constructor - } - else { - val constructor = DescriptorResolver.createAndRecordPrimaryConstructorForObject(classOrObject, thisDescriptor, trace) - setDeferredReturnType(constructor) - return constructor } + return null } private fun resolveSecondaryConstructors(): Collection { @@ -321,6 +318,12 @@ public open class LazyClassMemberScope( override fun toString() = "lazy scope for class ${thisDescriptor.getName()}" default object { + private val GENERATE_CONSTRUCTORS_FOR = setOf(ClassKind.CLASS, + ClassKind.ANNOTATION_CLASS, + ClassKind.OBJECT, + ClassKind.ENUM_CLASS, + ClassKind.ENUM_ENTRY) + private val EXTRACT_FUNCTIONS: MemberExtractor = object : MemberExtractor { override fun extract(extractFrom: JetType, name: Name): Collection { return extractFrom.getMemberScope().getFunctions(name) diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.kt b/compiler/testData/diagnostics/tests/TraitWithConstructor.kt deleted file mode 100644 index 11bb77d3649..00000000000 --- a/compiler/testData/diagnostics/tests/TraitWithConstructor.kt +++ /dev/null @@ -1,7 +0,0 @@ -class C(val a: String) {} - -trait T1(val x: String) {} - -trait T2() {} - -trait T3(a: Int) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/TraitWithConstructor.txt b/compiler/testData/diagnostics/tests/TraitWithConstructor.txt deleted file mode 100644 index 913dd50cf1e..00000000000 --- a/compiler/testData/diagnostics/tests/TraitWithConstructor.txt +++ /dev/null @@ -1,30 +0,0 @@ -package - -internal final class C { - public constructor C(/*0*/ a: kotlin.String) - internal final val a: kotlin.String - 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 -} - -internal trait T1 { - public constructor T1(/*0*/ x: kotlin.String) - internal final val x: kotlin.String - 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 -} - -internal trait T2 { - 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 -} - -internal trait T3 { - public constructor T3(/*0*/ a: kotlin.Int) - 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/testData/psi/TraitConstructor.kt b/compiler/testData/psi/TraitConstructor.kt deleted file mode 100644 index 31fe90fd1ab..00000000000 --- a/compiler/testData/psi/TraitConstructor.kt +++ /dev/null @@ -1,2 +0,0 @@ -trait TestTrait(val a: Int, var b: String, c: Double) -trait TestTrait() \ No newline at end of file diff --git a/compiler/testData/psi/TraitConstructor.txt b/compiler/testData/psi/TraitConstructor.txt deleted file mode 100644 index c820aef5628..00000000000 --- a/compiler/testData/psi/TraitConstructor.txt +++ /dev/null @@ -1,50 +0,0 @@ -JetFile: TraitConstructor.kt - PACKAGE_DIRECTIVE - - CLASS - PsiElement(trait)('trait') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('TestTrait') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('a') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Int') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(var)('var') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('b') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('String') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('c') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Double') - PsiElement(RPAR)(')') - PsiWhiteSpace('\n') - CLASS - PsiElement(trait)('trait') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('TestTrait') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 06c3ba8ebe7..4c8eefbb73f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -563,12 +563,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } - @TestMetadata("TraitWithConstructor.kt") - public void testTraitWithConstructor() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/TraitWithConstructor.kt"); - doTest(fileName); - } - @TestMetadata("TypeInference.kt") public void testTypeInference() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/TypeInference.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java index ccc6f65c512..e6745ccf648 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java @@ -543,12 +543,6 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } - @TestMetadata("TraitConstructor.kt") - public void testTraitConstructor() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/TraitConstructor.kt"); - doParsingTest(fileName); - } - @TestMetadata("TryRecovery.kt") public void testTryRecovery() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/TryRecovery.kt");