[FIR] Fix self-type for enum

This commit is contained in:
Simon Ogorodnik
2019-11-19 21:07:32 +03:00
parent 26113b1e0f
commit dbf0742c00
23 changed files with 180 additions and 165 deletions
@@ -337,11 +337,7 @@ class DeclarationsConverter(
}
}
val defaultDelegatedSuperTypeRef = when {
modifiers.isEnum() && (classKind == ClassKind.CLASS || classKind == ClassKind.INTERFACE) -> implicitEnumType
modifiers.isAnnotation() && (classKind == ClassKind.CLASS || classKind == ClassKind.INTERFACE) -> implicitAnnotationType
else -> implicitAnyType
}
if (classKind == ClassKind.CLASS) {
classKind = when {
@@ -352,7 +348,6 @@ class DeclarationsConverter(
}
val className = identifier.nameAsSafeName(if (modifiers.isCompanion()) "Companion" else "")
superTypeRefs.ifEmpty { superTypeRefs += defaultDelegatedSuperTypeRef }
val isLocal = isClassLocal(classNode) { getParent() }
return withChildClassName(className) {
@@ -389,12 +384,31 @@ class DeclarationsConverter(
firClass.annotations += modifiers.annotations
firClass.typeParameters += firTypeParameters
firClass.joinTypeParameters(typeConstraints)
val selfType = null.toDelegatedSelfType(firClass)
val defaultDelegatedSuperTypeRef = when {
modifiers.isEnum() && (classKind == ClassKind.ENUM_CLASS) ->
FirResolvedTypeRefImpl(
source = null,
ConeClassLikeTypeImpl(
implicitEnumType.type.lookupTag,
arrayOf(selfType.coneTypeUnsafe()),
isNullable = false
)
)
modifiers.isAnnotation() && (classKind == ClassKind.ANNOTATION_CLASS) -> implicitAnnotationType
else -> implicitAnyType
}
superTypeRefs.ifEmpty { superTypeRefs += defaultDelegatedSuperTypeRef }
firClass.superTypeRefs += superTypeRefs
val classWrapper = ClassWrapper(
className, modifiers, classKind, primaryConstructor != null,
classBody.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(),
null.toDelegatedSelfType(firClass),
selfType,
delegatedSuperTypeRef ?: defaultDelegatedSuperTypeRef, superTypeCallEntry
)
//parse primary constructor
@@ -520,11 +534,7 @@ class DeclarationsConverter(
)
firEnumEntry.annotations += modifiers.annotations
val defaultDelegatedSuperTypeRef = when {
modifiers.isEnum() -> implicitEnumType
modifiers.isAnnotation() -> implicitAnnotationType
else -> implicitAnyType
}
val defaultDelegatedSuperTypeRef = implicitAnyType
val enumClassWrapper = ClassWrapper(
enumEntryName, modifiers, ClassKind.ENUM_ENTRY, hasPrimaryConstructor = true,