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
56 lines
1.4 KiB
Kotlin
Vendored
56 lines
1.4 KiB
Kotlin
Vendored
/*
|
|
* UNEXPECTED BEHAVIOUR
|
|
* ISSUES: KT-37081
|
|
*/
|
|
|
|
|
|
enum class A {
|
|
A1,
|
|
A2,
|
|
}
|
|
class B()
|
|
class C(val b : B)
|
|
fun get(f: Boolean) = if (f) {A.A1} else {""}
|
|
|
|
<!CONFLICTING_OVERLOADS!>fun case2()<!> {
|
|
|
|
val flag: Any = get(false) //string
|
|
val l1 = <!NO_ELSE_IN_WHEN!>when<!> (flag<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) { // should be NO_ELSE_IN_WHEN
|
|
A.A1 -> B()
|
|
A.A2 -> B()
|
|
}
|
|
|
|
val l2 = <!NO_ELSE_IN_WHEN!>when<!> (flag) {// should be NO_ELSE_IN_WHEN
|
|
A.A1 -> B()
|
|
A.A2 -> B()
|
|
}
|
|
}
|
|
|
|
<!CONFLICTING_OVERLOADS!>fun case2()<!> {
|
|
|
|
val flag: Any = get(true) //A
|
|
val l1 = <!NO_ELSE_IN_WHEN!>when<!> (flag<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) {// should be NO_ELSE_IN_WHEN
|
|
A.A1 -> B()
|
|
A.A2 -> B()
|
|
}
|
|
|
|
val l2 = <!NO_ELSE_IN_WHEN!>when<!> (flag) {// should be NO_ELSE_IN_WHEN
|
|
A.A1 -> B()
|
|
A.A2 -> B()
|
|
}
|
|
}
|
|
|
|
fun case3() {
|
|
|
|
val flag = "" //A
|
|
val l1 = <!NO_ELSE_IN_WHEN!>when<!> (flag<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) {// should be NO_ELSE_IN_WHEN
|
|
<!INCOMPATIBLE_TYPES!>A.A1<!> -> B() //should be INCOMPATIBLE_TYPES
|
|
<!INCOMPATIBLE_TYPES!>A.A2<!> -> B() //should be INCOMPATIBLE_TYPES
|
|
}
|
|
|
|
val l2 = <!NO_ELSE_IN_WHEN!>when<!> (flag) {// should be NO_ELSE_IN_WHEN
|
|
<!INCOMPATIBLE_TYPES!>A.A1<!> -> B() //should be INCOMPATIBLE_TYPES
|
|
<!INCOMPATIBLE_TYPES!>A.A2<!> -> B() //should be INCOMPATIBLE_TYPES
|
|
}
|
|
}
|