[FIR] Implement RECURSIVE_TYPEALIAS_EXPANSION, CYCLIC_INHERITANCE_HIERARCHY diagnostics, fix stackoverlow exception in case if typealias points to type with type arguments
This commit is contained in:
committed by
teamcityserver
parent
d1531f9cdd
commit
c4c2fbb5a0
+12
@@ -407,6 +407,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.CYCLIC_INHERITANCE_HIERARCHY) { firDiagnostic ->
|
||||
CyclicInheritanceHierarchyImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.CONSTRUCTOR_IN_OBJECT) { firDiagnostic ->
|
||||
ConstructorInObjectImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
@@ -2378,6 +2384,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.RECURSIVE_TYPEALIAS_EXPANSION) { firDiagnostic ->
|
||||
RecursiveTypealiasExpansionImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.REDUNDANT_VISIBILITY_MODIFIER) { firDiagnostic ->
|
||||
RedundantVisibilityModifierImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
|
||||
+8
@@ -303,6 +303,10 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract val reason: String
|
||||
}
|
||||
|
||||
abstract class CyclicInheritanceHierarchy : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = CyclicInheritanceHierarchy::class
|
||||
}
|
||||
|
||||
abstract class ConstructorInObject : KtFirDiagnostic<KtDeclaration>() {
|
||||
override val diagnosticClass get() = ConstructorInObject::class
|
||||
}
|
||||
@@ -1670,6 +1674,10 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = ToplevelTypealiasesOnly::class
|
||||
}
|
||||
|
||||
abstract class RecursiveTypealiasExpansion : KtFirDiagnostic<KtTypeAlias>() {
|
||||
override val diagnosticClass get() = RecursiveTypealiasExpansion::class
|
||||
}
|
||||
|
||||
abstract class RedundantVisibilityModifier : KtFirDiagnostic<KtModifierListOwner>() {
|
||||
override val diagnosticClass get() = RedundantVisibilityModifier::class
|
||||
}
|
||||
|
||||
+14
@@ -472,6 +472,13 @@ internal class SupertypeNotAClassOrInterfaceImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class CyclicInheritanceHierarchyImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.CyclicInheritanceHierarchy(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class ConstructorInObjectImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
@@ -2703,6 +2710,13 @@ internal class ToplevelTypealiasesOnlyImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class RecursiveTypealiasExpansionImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.RecursiveTypealiasExpansion(), KtAbstractFirDiagnostic<KtTypeAlias> {
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class RedundantVisibilityModifierImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
interface A {
|
||||
fun foo() {}
|
||||
}
|
||||
interface B : A, E {}
|
||||
interface C : <error descr="[OTHER_ERROR] Unknown (other) error">B</error> {}
|
||||
interface D : <error descr="[OTHER_ERROR] Unknown (other) error">B</error> {}
|
||||
interface E : F {}
|
||||
interface F : D, C {}
|
||||
interface B : A, <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">E</error> {}
|
||||
interface C : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">B</error> {}
|
||||
interface D : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">B</error> {}
|
||||
interface E : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">F</error> {}
|
||||
interface F : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">D</error>, <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">C</error> {}
|
||||
interface G : F {}
|
||||
interface H : F {}
|
||||
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
// KT-303 Stack overflow on a cyclic class hierarchy
|
||||
|
||||
open class Foo() : Bar() {
|
||||
open class Foo() : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">Bar</error>() {
|
||||
val a : Int = 1
|
||||
}
|
||||
|
||||
open class Bar() : <error descr="[OTHER_ERROR] Unknown (other) error">Foo</error>() {
|
||||
open class Bar() : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">Foo</error>() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
class A : <error descr="[OTHER_ERROR] Unknown (other) error">A</error>() {}
|
||||
class A : <error descr="[CYCLIC_INHERITANCE_HIERARCHY] There's a cycle in the inheritance hierarchy for this type">A</error>() {}
|
||||
|
||||
val x : Int = <error descr="[INITIALIZER_TYPE_MISMATCH] Initializer type mismatch: expected kotlin/Int, actual A"><error descr="[TYPE_MISMATCH] Type mismatch: inferred type is A but kotlin/Int was expected">A()</error></error>
|
||||
|
||||
Reference in New Issue
Block a user