[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
Vendored
+3
@@ -7,4 +7,7 @@ class B : I
|
||||
fun test(a: A, b: B) {
|
||||
a == b
|
||||
a == b as I
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>a === b<!>
|
||||
a === b as I
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -7,4 +7,7 @@ class B : I
|
||||
fun test(a: A, b: B) {
|
||||
<!EQUALITY_NOT_APPLICABLE!>a == b<!>
|
||||
a == b as I
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>a === b<!>
|
||||
a === b as I
|
||||
}
|
||||
|
||||
@@ -11,4 +11,7 @@ class A
|
||||
fun main(args: Array<String>) {
|
||||
(1 to A()) == A()
|
||||
(1 to B()) == B()
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to A()) === A()<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to B()) === B()<!>
|
||||
}
|
||||
|
||||
@@ -11,4 +11,7 @@ class A
|
||||
fun main(args: Array<String>) {
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to A()) == A()<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to B()) == B()<!>
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to A()) === A()<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>(1 to B()) === B()<!>
|
||||
}
|
||||
|
||||
@@ -7,4 +7,9 @@ fun test() {
|
||||
if (Triple(0, 1, 2) == Pair(Foo.A, "a")) println("Doesn't compile")
|
||||
if (Triple(0, 1, 2) == Pair("a", "b")) println("Doesn't compile")
|
||||
if (Triple(Foo.A, 1, 2) == Pair(Foo.A, "a")) println("Compiles, but why?")
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(Foo.A, 1, 2) === Pair("a", "b")<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) === Pair(Foo.A, "a")<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) === Pair("a", "b")<!>
|
||||
<!EQUALITY_NOT_APPLICABLE_WARNING!>Triple(Foo.A, 1, 2) === Pair(Foo.A, "a")<!>
|
||||
}
|
||||
|
||||
@@ -7,4 +7,9 @@ fun test() {
|
||||
if (<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) == Pair(Foo.A, "a")<!>) println("Doesn't compile")
|
||||
if (<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) == Pair("a", "b")<!>) println("Doesn't compile")
|
||||
if (Triple(Foo.A, 1, 2) == Pair(Foo.A, "a")) println("Compiles, but why?")
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(Foo.A, 1, 2) === Pair("a", "b")<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) === Pair(Foo.A, "a")<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>Triple(0, 1, 2) === Pair("a", "b")<!>
|
||||
Triple(Foo.A, 1, 2) === Pair(Foo.A, "a")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user