[FIR] Implement CLASS_CANNOT_BE_EXTENDED_DIRECTLY
This commit is contained in:
committed by
teamcityserver
parent
92d7a61b4f
commit
c3a6ba52f6
+3
@@ -124,6 +124,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val SUPERTYPE_INITIALIZED_IN_INTERFACE by error<KtTypeReference>()
|
||||
val INTERFACE_WITH_SUPERCLASS by error<KtTypeReference>()
|
||||
val FINAL_SUPERTYPE by error<KtTypeReference>()
|
||||
val CLASS_CANNOT_BE_EXTENDED_DIRECTLY by error<KtTypeReference> {
|
||||
parameter<FirRegularClassSymbol>("classSymbol")
|
||||
}
|
||||
val SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE by error<KtTypeReference>()
|
||||
val SINGLETON_IN_SUPERTYPE by error<KtTypeReference>()
|
||||
val NULLABLE_SUPERTYPE by error<KtTypeReference>(PositioningStrategy.QUESTION_MARK_BY_TYPE)
|
||||
|
||||
@@ -134,6 +134,7 @@ object FirErrors {
|
||||
val SUPERTYPE_INITIALIZED_IN_INTERFACE by error0<KtTypeReference>()
|
||||
val INTERFACE_WITH_SUPERCLASS by error0<KtTypeReference>()
|
||||
val FINAL_SUPERTYPE by error0<KtTypeReference>()
|
||||
val CLASS_CANNOT_BE_EXTENDED_DIRECTLY by error1<KtTypeReference, FirRegularClassSymbol>()
|
||||
val SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE by error0<KtTypeReference>()
|
||||
val SINGLETON_IN_SUPERTYPE by error0<KtTypeReference>()
|
||||
val NULLABLE_SUPERTYPE by error0<KtTypeReference>(SourceElementPositioningStrategies.QUESTION_MARK_BY_TYPE)
|
||||
|
||||
+5
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object FirSupertypesChecker : FirClassChecker() {
|
||||
@@ -106,6 +107,10 @@ object FirSupertypesChecker : FirClassChecker() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (symbol is FirRegularClassSymbol && symbol.classId == StandardClassIds.Enum) {
|
||||
reporter.reportOn(superTypeRef.source, FirErrors.CLASS_CANNOT_BE_EXTENDED_DIRECTLY, symbol, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -65,6 +65,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CAN_BE_VAL
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CAPTURED_MEMBER_VAL_INITIALIZATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CAPTURED_VAL_INITIALIZATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CATCH_PARAMETER_WITH_DEFAULT_VALUE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CLASS_CANNOT_BE_EXTENDED_DIRECTLY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CLASS_IN_SUPERTYPE_FOR_ENUM
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CLASS_LITERAL_LHS_NOT_A_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPONENT_FUNCTION_AMBIGUITY
|
||||
@@ -453,6 +454,7 @@ class FirDefaultErrorMessages {
|
||||
map.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes")
|
||||
map.put(INTERFACE_WITH_SUPERCLASS, "An interface cannot inherit from a class")
|
||||
map.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from")
|
||||
map.put(CLASS_CANNOT_BE_EXTENDED_DIRECTLY, "Class {0} cannot be extended directly", SYMBOL)
|
||||
map.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes")
|
||||
map.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton")
|
||||
map.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable")
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class Test1 : Enum<Test1>("", 0)
|
||||
|
||||
class Outer {
|
||||
class Test2 : Enum<Test2>("", 0)
|
||||
}
|
||||
|
||||
fun outer() {
|
||||
class Test3 : Enum<Test3>("", 0)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
class Test1 : <!CLASS_CANNOT_BE_EXTENDED_DIRECTLY!>Enum<Test1><!>("", 0)
|
||||
|
||||
class Outer {
|
||||
|
||||
+7
@@ -351,6 +351,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.CLASS_CANNOT_BE_EXTENDED_DIRECTLY) { firDiagnostic ->
|
||||
ClassCannotBeExtendedDirectlyImpl(
|
||||
firSymbolBuilder.classifierBuilder.buildClassLikeSymbol(firDiagnostic.a.fir),
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE) { firDiagnostic ->
|
||||
SupertypeIsExtensionFunctionTypeImpl(
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
|
||||
+5
@@ -266,6 +266,11 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = FinalSupertype::class
|
||||
}
|
||||
|
||||
abstract class ClassCannotBeExtendedDirectly : KtFirDiagnostic<KtTypeReference>() {
|
||||
override val diagnosticClass get() = ClassCannotBeExtendedDirectly::class
|
||||
abstract val classSymbol: KtClassLikeSymbol
|
||||
}
|
||||
|
||||
abstract class SupertypeIsExtensionFunctionType : KtFirDiagnostic<KtTypeReference>() {
|
||||
override val diagnosticClass get() = SupertypeIsExtensionFunctionType::class
|
||||
}
|
||||
|
||||
+8
@@ -408,6 +408,14 @@ internal class FinalSupertypeImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class ClassCannotBeExtendedDirectlyImpl(
|
||||
override val classSymbol: KtClassLikeSymbol,
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ClassCannotBeExtendedDirectly(), KtAbstractFirDiagnostic<KtTypeReference> {
|
||||
override val firDiagnostic: FirPsiDiagnostic by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class SupertypeIsExtensionFunctionTypeImpl(
|
||||
firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
|
||||
Reference in New Issue
Block a user