[FIR] Fix false negative sealed diagnostics
... in presence of typealiases. #KT-61921
This commit is contained in:
committed by
Space Team
parent
36c0c2c76b
commit
2d4646a285
+3
-2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
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.analysis.checkers.fullyExpandedClassId
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
@@ -35,7 +36,7 @@ object FirSealedSupertypeChecker : FirClassChecker() {
|
||||
private fun checkGlobalDeclaration(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val subclassPackage = declaration.classId.packageFqName
|
||||
for (superTypeRef in declaration.superTypeRefs) {
|
||||
val superClassId = superTypeRef.coneType.classId ?: continue
|
||||
val superClassId = superTypeRef.coneType.fullyExpandedClassId(context.session) ?: continue
|
||||
|
||||
if (superClassId.isLocal) {
|
||||
continue
|
||||
@@ -60,7 +61,7 @@ object FirSealedSupertypeChecker : FirClassChecker() {
|
||||
|
||||
private fun checkLocalDeclaration(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
for (it in declaration.superTypeRefs) {
|
||||
val classId = it.coneType.classId ?: continue
|
||||
val classId = it.coneType.fullyExpandedClassId(context.session) ?: continue
|
||||
|
||||
if (classId.isLocal) {
|
||||
continue
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
typealias TA = Sealed
|
||||
|
||||
sealed class Sealed {
|
||||
object First: Sealed()
|
||||
open class NonFirst: Sealed() {
|
||||
@@ -6,6 +8,7 @@ sealed class Sealed {
|
||||
object Third: NonFirst()
|
||||
fun foo(): Int {
|
||||
val s = object: <!SEALED_SUPERTYPE_IN_LOCAL_CLASS!>Sealed<!>() {}
|
||||
val s2 = object: <!SEALED_SUPERTYPE_IN_LOCAL_CLASS!>TA<!>() {}
|
||||
class Local: <!SEALED_SUPERTYPE_IN_LOCAL_CLASS!>Sealed<!>() {}
|
||||
return s.hashCode()
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package
|
||||
|
||||
public sealed class Sealed {
|
||||
protected constructor Sealed()
|
||||
public final val p: Sealed
|
||||
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
|
||||
|
||||
public object First : Sealed {
|
||||
private constructor First()
|
||||
public final override /*1*/ /*fake_override*/ val p: Sealed
|
||||
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
|
||||
}
|
||||
|
||||
public open class NonFirst : Sealed {
|
||||
public constructor NonFirst()
|
||||
public final override /*1*/ /*fake_override*/ val p: Sealed
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public object Second : Sealed.NonFirst {
|
||||
private constructor Second()
|
||||
public final override /*1*/ /*fake_override*/ val p: Sealed
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public object Third : Sealed.NonFirst {
|
||||
private constructor Third()
|
||||
public final override /*1*/ /*fake_override*/ val p: Sealed
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun foo(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,7 @@ package bar
|
||||
|
||||
import foo.Base
|
||||
|
||||
typealias TA = Base
|
||||
|
||||
class E : <!SEALED_INHERITOR_IN_DIFFERENT_PACKAGE!>Base<!>()
|
||||
class E2 : <!SEALED_INHERITOR_IN_DIFFERENT_PACKAGE!>TA<!>()
|
||||
|
||||
@@ -37,4 +37,7 @@ package bar
|
||||
|
||||
import foo.Base
|
||||
|
||||
typealias TA = Base
|
||||
|
||||
class E : <!SEALED_INHERITOR_IN_DIFFERENT_PACKAGE!>Base<!>()
|
||||
class E2 : <!SEALED_INHERITOR_IN_DIFFERENT_PACKAGE!>TA<!>()
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package
|
||||
|
||||
package bar {
|
||||
|
||||
public final class E : foo.Base {
|
||||
public constructor E()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
package foo {
|
||||
|
||||
public final class B : foo.Base {
|
||||
public constructor B()
|
||||
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
|
||||
}
|
||||
|
||||
public sealed class Base {
|
||||
protected constructor Base()
|
||||
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
|
||||
|
||||
public final class A : foo.Base {
|
||||
public constructor A()
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
public final class Container {
|
||||
public constructor Container()
|
||||
public final val anon: foo.Base
|
||||
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 final fun someFun(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
public final class C : foo.Base {
|
||||
public constructor C()
|
||||
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
|
||||
}
|
||||
|
||||
public final inner class D : foo.Base {
|
||||
public constructor D()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user