K2: fix SUPERTYPE_NOT_INITIALIZED not being reported on object expressions ^KT-55597 Fixed
This commit is contained in:
committed by
Space Team
parent
868fe913f1
commit
2a724787f0
+1
-1
@@ -52,7 +52,7 @@ fun lol(a: Array<Boolean>) {}
|
||||
|
||||
class M {
|
||||
companion <!REDECLARATION!>object<!> {}
|
||||
val <!REDECLARATION!>Companion<!> = object : Any {}
|
||||
val <!REDECLARATION!>Companion<!> = object : Any() {}
|
||||
}
|
||||
|
||||
fun B.foo() {}
|
||||
|
||||
+1
-1
@@ -92,6 +92,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
FirImplementationMismatchChecker,
|
||||
FirTypeParametersInObjectChecker,
|
||||
FirSupertypesChecker,
|
||||
FirPrimaryConstructorSuperTypeChecker,
|
||||
)
|
||||
|
||||
override val regularClassCheckers: Set<FirRegularClassChecker>
|
||||
@@ -106,7 +107,6 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
|
||||
FirManyCompanionObjectsChecker,
|
||||
FirMethodOfAnyImplementedInInterfaceChecker,
|
||||
FirDataClassPrimaryConstructorChecker,
|
||||
FirPrimaryConstructorSuperTypeChecker,
|
||||
FirFunInterfaceDeclarationChecker,
|
||||
FirNestedClassChecker,
|
||||
FirValueClassDeclarationChecker,
|
||||
|
||||
+9
-6
@@ -7,12 +7,13 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.descriptors.isEnumEntry
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.SourceNavigator
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInterface
|
||||
import org.jetbrains.kotlin.fir.declarations.primaryConstructorIfAny
|
||||
@@ -23,8 +24,8 @@ import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
|
||||
|
||||
/** Checker on super type declarations in the primary constructor of a class declaration. */
|
||||
object FirPrimaryConstructorSuperTypeChecker : FirRegularClassChecker() {
|
||||
override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
object FirPrimaryConstructorSuperTypeChecker : FirClassChecker() {
|
||||
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (declaration.isInterface) {
|
||||
with(SourceNavigator.forElement(declaration)) {
|
||||
for (superTypeRef in declaration.superTypeRefs) {
|
||||
@@ -36,6 +37,8 @@ object FirPrimaryConstructorSuperTypeChecker : FirRegularClassChecker() {
|
||||
return
|
||||
}
|
||||
|
||||
if (declaration.classKind.isEnumEntry) return
|
||||
|
||||
val primaryConstructorSymbol = declaration.primaryConstructorIfAny(context.session)
|
||||
|
||||
if (primaryConstructorSymbol == null) {
|
||||
@@ -56,7 +59,7 @@ object FirPrimaryConstructorSuperTypeChecker : FirRegularClassChecker() {
|
||||
*/
|
||||
private fun checkSuperTypeNotInitialized(
|
||||
primaryConstructorSymbol: FirConstructorSymbol,
|
||||
regularClass: FirRegularClass,
|
||||
regularClass: FirClass,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
@@ -84,7 +87,7 @@ object FirPrimaryConstructorSuperTypeChecker : FirRegularClassChecker() {
|
||||
/**
|
||||
* SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR is reported on code like the following, where `B` does not have a primary
|
||||
* constructor, in which case, one can not call the delegated constructor of `A` in the super type list. `B` doesn't have a primary
|
||||
* constructor because it doesn't declare it, nor is it implicitly created in presence of a explicitly declared constructor inside the
|
||||
* constructor because it doesn't declare it, nor is it implicitly created in presence of an explicitly declared constructor inside the
|
||||
* class body.
|
||||
*
|
||||
* ```
|
||||
@@ -95,7 +98,7 @@ object FirPrimaryConstructorSuperTypeChecker : FirRegularClassChecker() {
|
||||
* ```
|
||||
*/
|
||||
private fun checkSupertypeInitializedWithoutPrimaryConstructor(
|
||||
regularClass: FirRegularClass,
|
||||
regularClass: FirClass,
|
||||
reporter: DiagnosticReporter,
|
||||
context: CheckerContext
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user