[FIR] Check typealiases in supertypes
^KT-59830 Fixed Merge-request: KT-MR-11187 Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
8a645e9c0a
commit
84dd1acec1
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+1
-1
@@ -12,4 +12,4 @@ package a
|
||||
|
||||
import b.TA
|
||||
|
||||
class MyClass : TA()
|
||||
class MyClass : <!FINAL_SUPERTYPE!>TA<!>()
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
+11
-12
@@ -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()) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-59830
|
||||
|
||||
class OOO
|
||||
|
||||
typealias Alias = OOO
|
||||
|
||||
class Child : <!FINAL_SUPERTYPE!>Alias<!>() //K1: [FINAL_SUPERTYPE] This type is final, so it cannot be inherited from, no error in K2
|
||||
@@ -1,6 +0,0 @@
|
||||
interface IBase
|
||||
|
||||
typealias B = IBase
|
||||
|
||||
class Test1 : B
|
||||
class Test2 : IBase, B
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
interface IBase
|
||||
|
||||
typealias B = IBase
|
||||
|
||||
Generated
+6
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user