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
62 lines
2.0 KiB
Kotlin
Vendored
62 lines
2.0 KiB
Kotlin
Vendored
// LANGUAGE: +ProhibitConfusingSyntaxInWhenBranches
|
|
// DIAGNOSTICS: -INCOMPATIBLE_TYPES, -NON_EXHAUSTIVE_WHEN_STATEMENT, -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
|
|
// ISSUE: KT-48385
|
|
|
|
operator fun Boolean.plus(other: Boolean): Boolean = true
|
|
operator fun Boolean.minus(other: Boolean): Boolean = true
|
|
operator fun Boolean.times(other: Boolean): Boolean = true
|
|
operator fun Boolean.div(other: Boolean): Boolean = true
|
|
operator fun Boolean.rem(other: Boolean): Boolean = true
|
|
|
|
operator fun Boolean.rangeTo(other: Boolean): Boolean = true
|
|
|
|
fun Boolean.id(): Boolean = true
|
|
|
|
operator fun Boolean.inc(): Boolean = true
|
|
operator fun Boolean.dec(): Boolean = true
|
|
|
|
operator fun Boolean.plusAssign(other: Boolean) {}
|
|
operator fun Boolean.minusAssign(other: Boolean) {}
|
|
operator fun Boolean.timesAssign(other: Boolean) {}
|
|
operator fun Boolean.divAssign(other: Boolean) {}
|
|
operator fun Boolean.remAssign(other: Boolean) {}
|
|
|
|
operator fun Any?.contains(other: Any): Boolean = false
|
|
|
|
fun testWithSubject_ok(x: Boolean, y: Boolean?, any: Any, z: Boolean) {
|
|
when {
|
|
x.id() -> {}
|
|
<!CONDITION_TYPE_MISMATCH!>y?.id()<!> -> {}
|
|
<!CONDITION_TYPE_MISMATCH!>any as? Boolean<!> -> {}
|
|
any as Boolean -> {}
|
|
x * x -> {}
|
|
x / x -> {}
|
|
x % x -> {}
|
|
x + x -> {}
|
|
x - x -> {}
|
|
x..x -> {}
|
|
<!CONDITION_TYPE_MISMATCH!>y<!> -> {}
|
|
y ?: x -> {}
|
|
x in x -> {}
|
|
x !in x -> {}
|
|
x is String -> {}
|
|
x !is String -> {}
|
|
x <!OVERLOAD_RESOLUTION_AMBIGUITY!><<!> x -> {}
|
|
x <!OVERLOAD_RESOLUTION_AMBIGUITY!>><!> x -> {}
|
|
x <!OVERLOAD_RESOLUTION_AMBIGUITY!><=<!> x -> {}
|
|
x <!OVERLOAD_RESOLUTION_AMBIGUITY!>>=<!> x -> {}
|
|
x == x -> {}
|
|
x != x -> {}
|
|
<!DEPRECATED_IDENTITY_EQUALS!>x === x<!> -> {}
|
|
<!DEPRECATED_IDENTITY_EQUALS!>x !== x<!> -> {}
|
|
x && x -> {}
|
|
x || x -> {}
|
|
}
|
|
|
|
var b = z
|
|
<!NO_ELSE_IN_WHEN!>when<!> (z) {
|
|
b++ -> {}
|
|
b-- -> {}
|
|
}
|
|
}
|