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
60 lines
1.4 KiB
Kotlin
Vendored
60 lines
1.4 KiB
Kotlin
Vendored
/*
|
|
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
|
|
*
|
|
* SPEC VERSION: 0.1-152
|
|
* PRIMARY LINKS: expressions, when-expression -> paragraph 2 -> sentence 5
|
|
* expressions, when-expression -> paragraph 5 -> sentence 1
|
|
* expressions, when-expression -> paragraph 6 -> sentence 1
|
|
* expressions, when-expression -> paragraph 6 -> sentence 3
|
|
* expressions, when-expression -> paragraph 6 -> sentence 5
|
|
* expressions, when-expression -> paragraph 6 -> sentence 9
|
|
* expressions, when-expression -> paragraph 6 -> sentence 10
|
|
* expressions, when-expression -> paragraph 6 -> sentence 11
|
|
*/
|
|
|
|
fun Int.foo() : Boolean = true
|
|
|
|
fun foo() : Int {
|
|
val s = ""
|
|
val x = 1
|
|
when (x) {
|
|
is String -> 1
|
|
<!USELESS_IS_CHECK!>!is Int<!> -> 1
|
|
<!USELESS_IS_CHECK!>is Any?<!> -> 1
|
|
<!USELESS_IS_CHECK!>is Any<!> -> 1
|
|
<!INCOMPATIBLE_TYPES!>s<!> -> 1
|
|
1 -> 1
|
|
1 <!OVERLOAD_RESOLUTION_AMBIGUITY!>+<!> <!UNRESOLVED_REFERENCE!>a<!> -> 1
|
|
in 1..<!UNRESOLVED_REFERENCE!>a<!> -> 1
|
|
!in 1..<!UNRESOLVED_REFERENCE!>a<!> -> 1
|
|
else -> 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo()
|
|
|
|
fun test() {
|
|
val x = 1;
|
|
val s = "";
|
|
|
|
when (x) {
|
|
<!INCOMPATIBLE_TYPES!>s<!> -> 1
|
|
<!INCOMPATIBLE_TYPES!>""<!> -> 1
|
|
x -> 1
|
|
1 -> 1
|
|
}
|
|
|
|
val z = 1
|
|
|
|
when (z) {
|
|
<!ELSE_MISPLACED_IN_WHEN!>else<!> -> 1
|
|
1 -> 2
|
|
}
|
|
|
|
when (z) {
|
|
else -> 1
|
|
}
|
|
}
|