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
64 lines
2.2 KiB
Kotlin
Vendored
64 lines
2.2 KiB
Kotlin
Vendored
interface Buffered {
|
|
fun flush()
|
|
}
|
|
|
|
interface AIPowered {
|
|
fun getAvatarReleaseYear(): Int
|
|
}
|
|
|
|
enum class BufferedEnum : Buffered {
|
|
A, B;
|
|
override fun flush() {}
|
|
}
|
|
|
|
enum class UsualEnum {
|
|
C, D;
|
|
}
|
|
|
|
enum class CleverEnum : Buffered, AIPowered {
|
|
E, F;
|
|
override fun flush() {}
|
|
override fun getAvatarReleaseYear() = 2022
|
|
}
|
|
|
|
fun <P> processInfo1(info: String, printer: P) where P: Buffered, P: AIPowered {
|
|
<!EQUALITY_NOT_APPLICABLE!>printer == 20<!>
|
|
printer == BufferedEnum.A
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == UsualEnum.C<!>
|
|
printer == CleverEnum.E
|
|
}
|
|
|
|
fun <P> processInfo2(info: String, printer: P) where P: AIPowered, P: Buffered {
|
|
<!EQUALITY_NOT_APPLICABLE!>printer == 20<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == BufferedEnum.A<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == UsualEnum.C<!>
|
|
printer == CleverEnum.E
|
|
}
|
|
|
|
abstract class Printer {
|
|
abstract fun print(command: String)
|
|
}
|
|
|
|
fun <P> processInfo3(info: String, printer: P) where P: Buffered, P: Printer {
|
|
<!EQUALITY_NOT_APPLICABLE!>printer == 20<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == BufferedEnum.A<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == UsualEnum.C<!>
|
|
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>printer == CleverEnum.E<!>
|
|
}
|
|
|
|
fun test(a: Int, b: Any?) {
|
|
<!IMPLICIT_BOXING_IN_IDENTITY_EQUALS!>a === b<!>
|
|
}
|
|
|
|
fun <<!INCONSISTENT_TYPE_PARAMETER_BOUNDS, MISPLACED_TYPE_PARAMETER_CONSTRAINTS!><!CONFLICTING_UPPER_BOUNDS!>T<!>: <!FINAL_UPPER_BOUND!>Int<!><!>> rest(a: T, b: Any?) where T : <!FINAL_UPPER_BOUND, ONLY_ONE_CLASS_BOUND_ALLOWED!>String<!> {
|
|
a === b
|
|
}
|
|
|
|
fun <<!MISPLACED_TYPE_PARAMETER_CONSTRAINTS!>T: Any?<!>> nest(a: Int, b: T) where T : <!FINAL_UPPER_BOUND, ONLY_ONE_CLASS_BOUND_ALLOWED!>String<!> {
|
|
<!EQUALITY_NOT_APPLICABLE!>a === b<!>
|
|
}
|
|
|
|
fun <<!INCONSISTENT_TYPE_PARAMETER_BOUNDS, MISPLACED_TYPE_PARAMETER_CONSTRAINTS!><!CONFLICTING_UPPER_BOUNDS!>T<!>: <!FINAL_UPPER_BOUND!>Int<!><!>, <!MISPLACED_TYPE_PARAMETER_CONSTRAINTS!>K: Any?<!>> mest(a: T, b: K) where T : <!FINAL_UPPER_BOUND, ONLY_ONE_CLASS_BOUND_ALLOWED!>String<!>, K: <!FINAL_UPPER_BOUND, ONLY_ONE_CLASS_BOUND_ALLOWED!>Boolean<!> {
|
|
a === b
|
|
}
|