diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 41392e6f9df..8d80f87a19f 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -339,6 +339,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/fileDependencyRecursion.kt"); } + @Test + @TestMetadata("finalSupertype.kt") + public void testFinalSupertype() throws Exception { + runTest("compiler/testData/diagnostics/tests/finalSupertype.kt"); + } + @Test @TestMetadata("ForRangeConventions.kt") public void testForRangeConventions() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 53f07aef775..24794e624e8 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -339,6 +339,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/fileDependencyRecursion.kt"); } + @Test + @TestMetadata("finalSupertype.kt") + public void testFinalSupertype() throws Exception { + runTest("compiler/testData/diagnostics/tests/finalSupertype.kt"); + } + @Test @TestMetadata("ForRangeConventions.kt") public void testForRangeConventions() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/multifile/TypeAliasExpansion.kt b/compiler/fir/analysis-tests/testData/resolve/multifile/TypeAliasExpansion.kt index 1dc92a5aba5..8fbd4fb43fd 100644 --- a/compiler/fir/analysis-tests/testData/resolve/multifile/TypeAliasExpansion.kt +++ b/compiler/fir/analysis-tests/testData/resolve/multifile/TypeAliasExpansion.kt @@ -12,4 +12,4 @@ package a import b.TA -class MyClass : TA() +class MyClass : TA() diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 588bc8f5029..4907f4bb02e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -339,6 +339,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/fileDependencyRecursion.kt"); } + @Test + @TestMetadata("finalSupertype.kt") + public void testFinalSupertype() throws Exception { + runTest("compiler/testData/diagnostics/tests/finalSupertype.kt"); + } + @Test @TestMetadata("ForRangeConventions.kt") public void testForRangeConventions() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 346103fd0da..2a266523a58 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -339,6 +339,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/fileDependencyRecursion.kt"); } + @Test + @TestMetadata("finalSupertype.kt") + public void testFinalSupertype() throws Exception { + runTest("compiler/testData/diagnostics/tests/finalSupertype.kt"); + } + @Test @TestMetadata("ForRangeConventions.kt") public void testForRangeConventions() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt index 0fc88e55080..bd9e8fc3741 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt @@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirField import org.jetbrains.kotlin.fir.declarations.FirRegularClass +import org.jetbrains.kotlin.fir.declarations.fullyExpandedClass import org.jetbrains.kotlin.fir.declarations.utils.modality import org.jetbrains.kotlin.fir.declarations.utils.visibility import org.jetbrains.kotlin.fir.languageVersionSettings @@ -55,14 +56,17 @@ object FirSupertypesChecker : FirClassChecker() { reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, context) extensionFunctionSupertypeReported = true } - val lookupTag = (coneType as? ConeClassLikeType)?.lookupTag ?: continue - val superTypeSymbol = lookupTag.toSymbol(context.session) - if (superTypeSymbol is FirRegularClassSymbol) { - if (!superClassSymbols.add(superTypeSymbol)) { + checkAnnotationOnSuperclass(superTypeRef, context, reporter) + + val fullyExpandedType = coneType.fullyExpandedType(context.session) + val symbol = fullyExpandedType.toSymbol(context.session) + + if (symbol is FirRegularClassSymbol) { + if (!superClassSymbols.add(symbol)) { reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_APPEARS_TWICE, context) } - if (superTypeSymbol.classKind != ClassKind.INTERFACE) { + if (symbol.classKind != ClassKind.INTERFACE) { if (classAppeared) { reporter.reportOn(superTypeRef.source, FirErrors.MANY_CLASSES_IN_SUPERTYPE_LIST, context) } else { @@ -73,8 +77,8 @@ object FirSupertypesChecker : FirClassChecker() { interfaceWithSuperclassReported = true } } - val isObject = superTypeSymbol.classKind == ClassKind.OBJECT - if (!finalSupertypeReported && !isObject && superTypeSymbol.modality == Modality.FINAL) { + val isObject = symbol.classKind == ClassKind.OBJECT + if (!finalSupertypeReported && !isObject && symbol.modality == Modality.FINAL) { reporter.reportOn(superTypeRef.source, FirErrors.FINAL_SUPERTYPE, context) finalSupertypeReported = true } @@ -84,11 +88,6 @@ object FirSupertypesChecker : FirClassChecker() { } } - checkAnnotationOnSuperclass(superTypeRef, context, reporter) - - val fullyExpandedType = coneType.fullyExpandedType(context.session) - val symbol = fullyExpandedType.toSymbol(context.session) - checkClassCannotBeExtendedDirectly(symbol, reporter, superTypeRef, context) if (coneType.typeArguments.isNotEmpty()) { diff --git a/compiler/testData/diagnostics/tests/finalSupertype.kt b/compiler/testData/diagnostics/tests/finalSupertype.kt new file mode 100644 index 00000000000..af77127039d --- /dev/null +++ b/compiler/testData/diagnostics/tests/finalSupertype.kt @@ -0,0 +1,8 @@ +// FIR_IDENTICAL +// ISSUE: KT-59830 + +class OOO + +typealias Alias = OOO + +class Child : Alias() //K1: [FINAL_SUPERTYPE] This type is final, so it cannot be inherited from, no error in K2 diff --git a/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt b/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt deleted file mode 100644 index 728ecb7ff5a..00000000000 --- a/compiler/testData/diagnostics/tests/typealias/inSupertypesList.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -interface IBase - -typealias B = IBase - -class Test1 : B -class Test2 : IBase, B diff --git a/compiler/testData/diagnostics/tests/typealias/inSupertypesList.kt b/compiler/testData/diagnostics/tests/typealias/inSupertypesList.kt index e883f1258ee..0071f47af74 100644 --- a/compiler/testData/diagnostics/tests/typealias/inSupertypesList.kt +++ b/compiler/testData/diagnostics/tests/typealias/inSupertypesList.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface IBase typealias B = IBase diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 88a9d0c157a..afe0cc37dc0 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -339,6 +339,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/fileDependencyRecursion.kt"); } + @Test + @TestMetadata("finalSupertype.kt") + public void testFinalSupertype() throws Exception { + runTest("compiler/testData/diagnostics/tests/finalSupertype.kt"); + } + @Test @TestMetadata("ForRangeConventions.kt") public void testForRangeConventions() throws Exception {