[FIR] Fix K2 behavior according to RULES1

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
This commit is contained in:
Nikolay Lunyak
2023-02-01 18:21:53 +02:00
committed by Space Team
parent 06e687addd
commit f0720c1d12
86 changed files with 1982 additions and 594 deletions
@@ -161,7 +161,7 @@ inline fun <reified T>case_17(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_18(x: Any?) {
if (x?.equals(10) === null === true) else {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) === null === true<!>) else {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -173,7 +173,7 @@ inline fun <reified T>case_18(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_19(x: Any?) {
if (x?.equals(10) !== null === true) {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) !== null === true<!>) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -185,7 +185,7 @@ inline fun <reified T>case_19(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_20(x: Any?) {
if (x?.equals(10) === null !== false) else {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) === null !== false<!>) else {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -197,7 +197,7 @@ inline fun <reified T>case_20(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_21(x: Any?) {
if (x?.equals(10) !== null !== false) {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) !== null !== false<!>) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -209,7 +209,7 @@ inline fun <reified T>case_21(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_22(x: Any?) {
if (x?.equals(10) !== null !== true) else {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) !== null !== true<!>) else {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -221,7 +221,7 @@ inline fun <reified T>case_22(x: Any?) {
* ISSUES: KT-30369, KT-28262, KT-29878
*/
inline fun <reified T>case_23(x: Any?) {
if (x?.equals(10) === null === false) {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) === null === false<!>) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -257,7 +257,7 @@ inline fun <reified T>case_25(x: Any?) {
* ISSUES: KT-30369, KT-29878
*/
inline fun <reified T>case_26(x: Any?) {
if (x?.equals(10) != null === false) else {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) != null === false<!>) else {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}
@@ -269,7 +269,7 @@ inline fun <reified T>case_26(x: Any?) {
* ISSUES: KT-30369, KT-29878
*/
inline fun <reified T>case_27(x: Any?) {
if (x?.equals(10) == null === false) {
if (<!DEPRECATED_IDENTITY_EQUALS!>x?.equals(10) == null === false<!>) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any? & kotlin.Any")!>x<!>.equals(10)
}