diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt index 1498cc8462e..718ea6c5312 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt @@ -5,4 +5,4 @@ interface B : A interface C class D -interface E : A(), C, D() \ No newline at end of file +interface E : A(), C, D() \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedInInterface.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedInInterface.kt index 645d98e6754..c0c3ad4c722 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedInInterface.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/supertypeInitializedInInterface.kt @@ -8,6 +8,6 @@ interface D : C interface E : Any() -interface F : A, B(), C, D(), Any() { +interface F : A, B(), C, D(), Any() { } \ No newline at end of file diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypeInitializedInInterfaceChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypeInitializedInInterfaceChecker.kt index 276bc3f1a36..d81a167bab4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypeInitializedInInterfaceChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypeInitializedInInterfaceChecker.kt @@ -5,22 +5,14 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration -import com.intellij.lang.LighterASTNode -import com.intellij.psi.PsiElement -import com.intellij.psi.PsiErrorElement -import com.intellij.util.diff.FlyweightCapableTreeStructure import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.descriptors.ClassKind -import org.jetbrains.kotlin.fir.FirLightSourceElement import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext -import org.jetbrains.kotlin.fir.analysis.checkers.getChildren import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration -import org.jetbrains.kotlin.fir.psi -import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry object FirSupertypeInitializedInInterfaceChecker : FirMemberDeclarationChecker() { override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { @@ -28,42 +20,11 @@ object FirSupertypeInitializedInInterfaceChecker : FirMemberDeclarationChecker() return } - declaration.source?.findSuperTypeCall()?.let { - reporter.report(declaration.superTypeRefs.getOrNull(it)?.source) - } - } - - private fun FirSourceElement.findSuperTypeCall(): Int { - val localPsi = psi - val localLightNode = lighterASTNode - - if (localPsi != null && localPsi !is PsiErrorElement) { - return localPsi.findSuperTypeCall() - } else if (this is FirLightSourceElement) { - return localLightNode.findSuperTypeCall(treeStructure) - } - - return -1 - } - - private fun PsiElement.findSuperTypeCall(): Int { - val children = this.children // this is a method call and it collects children - return if (children.isNotEmpty() && children[0] !is PsiErrorElement) { - children[0].children.indexOfFirst { it is KtSuperTypeCallEntry } - } else { - -1 - } - } - - private fun LighterASTNode.findSuperTypeCall(tree: FlyweightCapableTreeStructure): Int { - val children = getChildren(tree) - return if (children.isNotEmpty()) { - children.find { it?.tokenType == KtNodeTypes.SUPER_TYPE_LIST } - ?.getChildren(tree) - ?.indexOfFirst { it?.tokenType == KtNodeTypes.SUPER_TYPE_CALL_ENTRY } - ?: -1 - } else { - -1 + for (superTypeRef in declaration.superTypeRefs) { + val source = superTypeRef.source ?: continue + if (source.treeStructure.getParent(source.lighterASTNode)?.tokenType == KtNodeTypes.CONSTRUCTOR_CALLEE) { + reporter.report(source) + } } } diff --git a/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt b/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt index d1a66fcaece..abca9fd22b6 100644 --- a/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt +++ b/compiler/testData/diagnostics/tests/traitWithRequired/traitSupertypeList.fir.kt @@ -1,6 +1,6 @@ open class bar() -interface Foo() : bar(), bar, bar { +interface Foo() : bar(), bar, bar { } interface Foo2 : bar, Foo {