[FIR] When call candidates resolve to errors, select the least bad ones

This fixes a scenario when INVISIBLE_REFERENCE is suppressed, but we
resolved to the wrong overload because when none of the candidates were
applicable, more or less the first one was chosen.

Because we call `fullyProcessCandidate` on the candidates, their
applicability can change which can lead to a situation where the
applicability of a ConeAmbiguityError is different to all its
candidates. The changes in coneDiagnosticToFirDiagnostic.kt account for
that, otherwise code like candidates.first { it.applicability ==
CandidateApplicability.UNSAFE_CALL } can throw NoSuchElementException.

#KT-57776 Fixed
This commit is contained in:
Kirill Rakhman
2023-04-05 17:21:24 +02:00
committed by Space Team
parent 09ea0ef757
commit 592baee852
24 changed files with 345 additions and 52 deletions
@@ -0,0 +1,11 @@
// MODULE: a
// FILE: a.kt
internal fun foo(s: String) = "FAIL"
internal fun foo(s: String, x: Any) = "OK"
// MODULE: b(a)
// FILE: box.kt
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun box() = foo("", Any())
@@ -6,7 +6,7 @@ class A {
}
fun test(a: A) {
a.<!NONE_APPLICABLE!>foo<!>(3)
a.<!INVISIBLE_REFERENCE!>foo<!>(3)
a.<!NONE_APPLICABLE!>foo<!>()
}
@@ -7,7 +7,7 @@ open class A protected constructor(x: Int) {
}
fun foo() {
<!NONE_APPLICABLE!>A<!>()
<!INVISIBLE_REFERENCE!>A<!>()
A(1.0)
}
@@ -9,11 +9,11 @@ open class MyClass private constructor(val x: Int) {
typealias MyAlias = MyClass
val test1 = <!NONE_APPLICABLE!>MyAlias<!>(1)
val test1a = <!NONE_APPLICABLE!>MyClass<!>(1)
val test1 = <!INVISIBLE_REFERENCE!>MyAlias<!>(1)
val test1a = <!INVISIBLE_REFERENCE!>MyClass<!>(1)
val test2 = <!NONE_APPLICABLE!>MyAlias<!>("")
val test2a = <!NONE_APPLICABLE!>MyClass<!>("")
val test2 = <!INVISIBLE_REFERENCE!>MyAlias<!>("")
val test2a = <!INVISIBLE_REFERENCE!>MyClass<!>("")
val test3 = MyAlias(1.0)
val test3a = MyClass(1.0)