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
|
||||
) {
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ fun test() {
|
||||
val x9: (Foo<Float>) -> Int = { x: Foo<<!UNDERSCORE_USAGE_WITHOUT_BACKTICKS, UNRESOLVED_REFERENCE!>_<!>> -> 10 }
|
||||
|
||||
val x10 = object : <!UNRESOLVED_REFERENCE!>_<!> {}
|
||||
val x11 = object : <!FINAL_SUPERTYPE!>Foo<<!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>_<!>><!> {}
|
||||
val x11 = object : <!FINAL_SUPERTYPE!>Foo<<!UNRESOLVED_REFERENCE!>_<!>><!>() {}
|
||||
|
||||
if (x11 is <!UNRESOLVED_REFERENCE!>_<!>) { }
|
||||
if (<!USELESS_IS_CHECK!>x11 is Foo<<!UNRESOLVED_REFERENCE!>_<!>><!>) { }
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ fun test() {
|
||||
val x9: (Foo<Float>) -> Int = { x: Foo<<!UNRESOLVED_REFERENCE!>_<!>> -> 10 }
|
||||
|
||||
val x10 = object : <!UNRESOLVED_REFERENCE!>_<!> {}
|
||||
val x11 = object : <!FINAL_SUPERTYPE, SUPERTYPE_NOT_INITIALIZED!>Foo<<!UNRESOLVED_REFERENCE!>_<!>><!> {}
|
||||
val x11 = object : <!FINAL_SUPERTYPE!>Foo<<!UNRESOLVED_REFERENCE!>_<!>><!>() {}
|
||||
|
||||
if (x11 is <!UNRESOLVED_REFERENCE!>_<!>) { }
|
||||
if (x11 is <!INCOMPATIBLE_TYPES!>Foo<<!UNRESOLVED_REFERENCE!>_<!>><!>) { }
|
||||
|
||||
@@ -17,6 +17,8 @@ class T : <!NO_VALUE_FOR_PARAMETER, SUPERTYPE_NOT_INITIALIZED!>Foo<!> {}
|
||||
|
||||
object B : <!SINGLETON_IN_SUPERTYPE!>A<!> {}
|
||||
|
||||
val c = <!NO_VALUE_FOR_PARAMETER{LT}!>object : <!NO_VALUE_FOR_PARAMETER{PSI}, SUPERTYPE_NOT_INITIALIZED!>Foo<!> {}<!>
|
||||
|
||||
val x = A.foo()
|
||||
|
||||
val y = object : Foo(x) {
|
||||
|
||||
@@ -17,6 +17,8 @@ object A : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> {
|
||||
|
||||
object B : <!SINGLETON_IN_SUPERTYPE!>A<!> {}
|
||||
|
||||
val c = object : <!SUPERTYPE_NOT_INITIALIZED!>Foo<!> {}
|
||||
|
||||
val x = A.foo()
|
||||
|
||||
val y = object : Foo(x) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package
|
||||
|
||||
package toplevelObjectDeclarations {
|
||||
public val c: toplevelObjectDeclarations.Foo
|
||||
public val x: kotlin.Int
|
||||
public val y: toplevelObjectDeclarations.Foo
|
||||
public val z: kotlin.Int
|
||||
|
||||
@@ -36,6 +36,9 @@ inline val ClassKind.isInterface: Boolean
|
||||
inline val ClassKind.isEnumClass: Boolean
|
||||
get() = this == ClassKind.ENUM_CLASS
|
||||
|
||||
inline val ClassKind.isEnumEntry: Boolean
|
||||
get() = this == ClassKind.ENUM_ENTRY
|
||||
|
||||
inline val ClassKind.isAnnotationClass: Boolean
|
||||
get() = this == ClassKind.ANNOTATION_CLASS
|
||||
|
||||
|
||||
Reference in New Issue
Block a user