Revert "Generate descriptor for trait constructor. Exception is thrown otherwise (EA-38416)"
This reverts commit 6ba120bba8.
This commit is contained in:
+23
-20
@@ -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<ConstructorDescriptor> {
|
||||
@@ -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<FunctionDescriptor> = object : MemberExtractor<FunctionDescriptor> {
|
||||
override fun extract(extractFrom: JetType, name: Name): Collection<FunctionDescriptor> {
|
||||
return extractFrom.getMemberScope().getFunctions(name)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
class C(val a: String) {}
|
||||
|
||||
trait T1<!CONSTRUCTOR_IN_TRAIT!>(val x: String)<!> {}
|
||||
|
||||
trait T2<!CONSTRUCTOR_IN_TRAIT!>()<!> {}
|
||||
|
||||
trait T3<!CONSTRUCTOR_IN_TRAIT!>(<!UNUSED_PARAMETER!>a<!>: Int)<!> {}
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
trait TestTrait(val a: Int, var b: String, c: Double)
|
||||
trait TestTrait()
|
||||
@@ -1,50 +0,0 @@
|
||||
JetFile: TraitConstructor.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
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)(')')
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user