From bb812add14748f1fa7b767b995dd80d17d4dc79c Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Mon, 26 Feb 2024 16:12:55 +0200 Subject: [PATCH] [FIR] Don't miss modality of anonymous objects in `canHaveSubtypes()` They are not `FirRegularClassSymbol`, but are final. `FirClassSymbol` is enough, because `toSymbol()` returns `FirClassifierSymbol`, and: - type parameters are always expected to have subtypes - typealiases have been expanded in the previous line --- .../jetbrains/kotlin/fir/types/TypeUtils.kt | 2 +- .../enum/incompatibleEnumEntryClasses.fir.kt | 92 ------------------- .../enum/incompatibleEnumEntryClasses.kt | 1 + .../diagnostics/notLinked/dfa/pos/6.fir.kt | 2 +- 4 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 6df5ece3d9f..057d060130f 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -592,7 +592,7 @@ fun ConeKotlinType.canHaveSubtypes(session: FirSession): Boolean { return true } val expandedType = fullyExpandedType(session) - val classSymbol = expandedType.toSymbol(session) as? FirRegularClassSymbol ?: return true + val classSymbol = expandedType.toSymbol(session) as? FirClassSymbol ?: return true // In K2 enum classes are final, though enum entries are their subclasses (which is a compiler implementation detail). if (classSymbol.isEnumClass || classSymbol.isExpect || classSymbol.modality != Modality.FINAL) { return true diff --git a/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt b/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt deleted file mode 100644 index b9a289accf0..00000000000 --- a/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.fir.kt +++ /dev/null @@ -1,92 +0,0 @@ -// !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums - -interface I { - fun foo() -} - -enum class E1 : I { - A { - override fun foo() { - this == E2.A - - val q = this - when (q) { - this -> {} - E1.A -> {} - E1.B -> {} - E2.A -> {} - E2.B -> {} - else -> {} - } - } - }, - B { - override fun foo() { - - } - } -} - -enum class E2 : I { - A { - override fun foo() { - - } - }, - B { - override fun foo() { - - } - } -} - -fun foo1(e1: E1, e2: E2) { - e1 == e2 - e1 != e2 - - e1 == E2.A - E1.B == e2 - - E1.A == E2.B - - e1 == E1.A - E1.A == e1 - e2 == E2.B - E2.B == e2 -} - -fun foo2(e1: E1, e2: E2) { - when (e1) { - E1.A -> {} - E2.A -> {} - E2.B -> {} - e1 -> {} - e2 -> {} - else -> {} - } -} - -fun foo3(e1: Enum, e2: Enum, e: Enum<*>) { - e1 == e - e1 == e2 - - e1 == E1.A - e1 == E2.A - - when (e1) { - e1 -> {} - e2 -> {} - e -> {} - E1.A -> {} - E2.A -> {} - else -> {} - } - - when (e) { - e -> {} - e2 -> {} - E1.A -> {} - E2.A -> {} - else -> {} - } -} diff --git a/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.kt b/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.kt index d206c690a01..142407b797a 100644 --- a/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.kt +++ b/compiler/testData/diagnostics/tests/enum/incompatibleEnumEntryClasses.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums interface I { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt index deb9d33e453..fa261b8585b 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt @@ -585,7 +585,7 @@ fun case_29(x: Boolean) { if (false || false || false || false || y !== v) { val t = ?")!>y() - if (z !== t || false) { + if (z !== t || false) { ?")!>t.a ?")!>t.equals(null) ?")!>t.propT