[FIR] Forbid erroneous ===-checks
It was decided to forbid such comparisons, as we know how `===` works. Also, added some more test cases, just for comparison. Reusing the proper `canHaveSubtypes()` from `TypeUtils` prevents a breaking change in: - `comparingTripleWithPair.kt` - `comparisonOfGenericInterfaceWithGenericClass.kt` But it does lead to warnings (instead of errors) in `incompatibleEnumEntryClasses.kt`, which is an unrelated mistake that will be fixed in the next commit. The refactoring in `canHaveSubtypes()` is purely cosmetic - otherwise reading these conditions is hard (and they don't fit my screen vertically). ^KT-62646 ^KT-65541 ^KT-57779
This commit is contained in:
committed by
Space Team
parent
6bf987e772
commit
226d4df277
@@ -26,6 +26,11 @@ fun <P> processInfo1(info: String, printer: P) where P: Buffered, P: AIPowered {
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == UsualEnum.C<!>
|
||||
printer == CleverEnum.E
|
||||
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>printer === 20<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === UsualEnum.C<!>
|
||||
printer === CleverEnum.E
|
||||
}
|
||||
|
||||
fun <P> processInfo2(info: String, printer: P) where P: AIPowered, P: Buffered {
|
||||
@@ -33,6 +38,11 @@ fun <P> processInfo2(info: String, printer: P) where P: AIPowered, P: Buffered {
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == UsualEnum.C<!>
|
||||
printer == CleverEnum.E
|
||||
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>printer === 20<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === UsualEnum.C<!>
|
||||
printer === CleverEnum.E
|
||||
}
|
||||
|
||||
abstract class Printer {
|
||||
@@ -44,6 +54,11 @@ fun <P> processInfo3(info: String, printer: P) where P: Buffered, P: Printer {
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == UsualEnum.C<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer == CleverEnum.E<!>
|
||||
|
||||
<!FORBIDDEN_IDENTITY_EQUALS!>printer === 20<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === BufferedEnum.A<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === UsualEnum.C<!>
|
||||
<!INCOMPATIBLE_ENUM_COMPARISON!>printer === CleverEnum.E<!>
|
||||
}
|
||||
|
||||
fun test(a: Int, b: Any?) {
|
||||
|
||||
Reference in New Issue
Block a user