[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
@@ -33,7 +33,7 @@ fun case1(javaClass: JavaClass?) {
}
class Case1(val javaClass: JavaClass?) {
val x = if (javaClass != null) { it -> <!EQUALITY_NOT_APPLICABLE_WARNING!>it == javaClass<!> } else BooCase2.FILTER
val x = if (javaClass != null) { it -> it == javaClass } else BooCase2.FILTER
}
class BooCase1() {
@@ -101,7 +101,7 @@ fun test_9(a: Int, b: Int?) {
}
b<!UNSAFE_CALL!>.<!>inc()
if (a === b) {
if (<!IMPLICIT_BOXING_IN_IDENTITY_EQUALS!>a === b<!>) {
b.inc()
}
b<!UNSAFE_CALL!>.<!>inc()
@@ -111,7 +111,7 @@ fun test_9(a: Int, b: Int?) {
}
b<!UNSAFE_CALL!>.<!>inc()
if (b === a) {
if (<!IMPLICIT_BOXING_IN_IDENTITY_EQUALS!>b === a<!>) {
b.inc()
}
b<!UNSAFE_CALL!>.<!>inc()
@@ -22,12 +22,12 @@ enum class Second {
val ONE = Second.THREE
fun foo(f: First) = <!NO_ELSE_IN_WHEN!>when<!> (f) {
<!INCOMPATIBLE_TYPES!>ONE<!> -> 1
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>ONE<!> -> 1
TWO -> 2
}
fun bar(s: Second) = <!NO_ELSE_IN_WHEN!>when<!> (s) {
<!INCOMPATIBLE_TYPES!>THREE<!> -> 3
<!INCOMPATIBLE_ENUM_COMPARISON_ERROR!>THREE<!> -> 3
FOUR -> 4
}
@@ -1,4 +1,3 @@
/*
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-37081