K2: Avoid false-positive overload resolution ambiguity with smart casts

The idea is that when we have successful candidates both from smart cast
and original type, we should discriminate in the favor of former ones.

While this problem (see kt55722.kt) existed before this branch is merged,
initially it was recognized on FP Ultimate when we stopped assuming
captured types from the same projections as equal (see kt55722Initial.kt).

^KT-55722 Fixed
^KT-55024 Fixed
^KT-56283 Related
^KT-56310 Related
This commit is contained in:
Denis.Zharkov
2023-01-02 12:00:14 +01:00
committed by Space Team
parent 7b6c6fceb6
commit b6b132a9a3
27 changed files with 1034 additions and 35 deletions
@@ -0,0 +1,26 @@
// SKIP_TXT
// FIR_DUMP
open class Base
class Derived : Base()
open class A(protected open val foo: Base) {
protected open fun bar(): Base = Base()
fun f(other: A) {
other.foo // OK in K1 and K2
other.bar() // OK in K1 and K2
when (other) {
is B -> {
// OK in K2, INVISIBLE_MEMBER (B::foo) in K1
<!DEBUG_INFO_SMARTCAST!>other<!>.<!INVISIBLE_MEMBER!>foo<!>
<!DEBUG_INFO_SMARTCAST!>other<!>.<!INVISIBLE_MEMBER!>bar<!>()
}
}
}
}
class B(override val foo: Derived): A(foo) {
override fun bar(): Derived = Derived()
}