f0720c1d12
The compiler should only report diagnostics for
comparisons over builtins and identity-less types,
other incompatibilities should be reported
via inspections.
It's ok that in `equalityChecksOnIntegerTypes`
instead of `EQUALITY_NOT_APPLICABLE_WARNING` we get
`EQUALITY_NOT_APPLICABLE`, because
`ProperEqualityChecksInBuilderInferenceCalls`
is already active by default.
This change also replaces the notion of a representative superclass
with the least upper bound.
This makes complex types like
intersection/flexible transparent to
RULES1-based compatibility checks.
One way to look at it is to think
that this is an automatic way of handling
type parameters: automatic picking of
"interesting" bounds, and checking them against one another.
Note that `TypeIntersector.intersectTypes`
for `Int` and `T` where `T` is a type parameter
may return both `{Int & T}` or `null`
depending on `T`-s bounds. At the same time,
for type parameters `T` and `K` it will
always return `{T & K}`.
`ConeTypeIntersector.intersectTypes`, on the
other hand, will always return `{Int & T}`
irrespectively of the bounds. Meaning, the two
intersectors differ in corner cases.
`lowerBoundIfFlexible` call in `isLiterallyTypeParameter` is backed by
the `equalityOfFlexibleTypeParameters` test.
^KT-35134 #fixed-in-k2
^KT-22499 #fixed-in-k2
^KT-46383 #fixed-in-k2
94 lines
1.6 KiB
Kotlin
Vendored
94 lines
1.6 KiB
Kotlin
Vendored
// FIR_IDENTICAL
|
|
// !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums
|
|
|
|
interface I {
|
|
fun foo()
|
|
}
|
|
|
|
enum class E1 : I {
|
|
A {
|
|
override fun foo() {
|
|
<!EQUALITY_NOT_APPLICABLE!>this == E2.A<!>
|
|
|
|
val q = this
|
|
when (q) {
|
|
this -> {}
|
|
E1.A -> {}
|
|
E1.B -> {}
|
|
<!INCOMPATIBLE_TYPES!>E2.A<!> -> {}
|
|
<!INCOMPATIBLE_TYPES!>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) {
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>e1 == e2<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>e1 != e2<!>
|
|
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>e1 == E2.A<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>E1.B == e2<!>
|
|
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>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 -> {}
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>E2.A<!> -> {}
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>E2.B<!> -> {}
|
|
e1 -> {}
|
|
<!INCOMPATIBLE_ENUM_COMPARISON!>e2<!> -> {}
|
|
else -> {}
|
|
}
|
|
}
|
|
|
|
fun foo3(e1: Enum<E1>, e2: Enum<E2>, 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 -> {}
|
|
}
|
|
}
|