KaCallResolutionAttempt
KaCallResolutionAttempt is the rich result type of tryResolveCall(). Unlike the plain resolveSuccessfulCall() — which collapses failures to null — an attempt always carries everything the compiler considered: either the resolved call, or a diagnostic together with candidate calls. For compound calls (for-loops, delegated properties, +=, array compound), the attempt additionally addresses each sub-call independently, so partial success is observable.
This page documents the sealed hierarchy and helper extensions. For the high-level view, see Resolving Calls.
Hierarchy
Simple-call attempts
KaSimpleCallResolutionAttempt
Sealed: either KaSimpleCallResolutionSuccess or KaSimpleCallResolutionError. Both KaSimpleCallResolutionSuccess.call and KaSimpleCallResolutionError.candidateCalls always contain KaSimpleCall instances.
KaSimpleCallResolutionSuccess
val call: KaSimpleCall<*, *>The resolved simple call.
KaSimpleCallResolutionError
val diagnostic: KaDiagnosticThe diagnostic associated with the error (e.g.
INVISIBLE_REFERENCE,UNRESOLVED_REFERENCE).val candidateCalls: List<KaSimpleCall<*, *>>The candidate calls the compiler considered. The list may be empty — an error does not have to expose candidates.
Multi-call attempts
KaMultiCallResolutionAttempt represents a compound or desugared call. When every sub-call resolves, the attempt assembles a KaMultiCall; when any sub-call fails, the assembled call is null but the individual sub-attempts remain addressable.
The concrete subtypes match the four kinds of compound calls:
KaForLoopCallResolutionAttempt
For a for (item in expr) loop. call is KaForLoopCall? — non-null only when all three sub-calls resolve.
Member | Description |
|---|---|
| Resolution attempt for the |
| Resolution attempt for the |
| Resolution attempt for the |
KaDelegatedPropertyCallResolutionAttempt
For a by-delegated property. call is KaDelegatedPropertyCall?.
Member | Description |
|---|---|
| Resolution attempt for the |
| Resolution attempt for the |
| Resolution attempt for the |
KaCompoundVariableAccessCallResolutionAttempt
For i += 1/i++/i-- on a variable. call is KaCompoundVariableAccessCall?.
Member | Description |
|---|---|
| Resolution attempt for the variable read/write. |
| Resolution attempt for the operator function ( |
KaCompoundArrayAccessCallResolutionAttempt
For a[i] += v and similar. call is KaCompoundArrayAccessCall?.
Member | Description |
|---|---|
| Resolution attempt for the |
| Resolution attempt for the operator function. |
| Resolution attempt for the |
Helper extensions
Six extension properties cover the common cases without forcing a pattern match.
val KaCallResolutionAttempt.calls: List<KaSimpleOrMultiCall>A flattened list of resolved/candidate calls. On
KaSimpleCallResolutionSuccessreturns the resolved call as a one-element list. OnKaSimpleCallResolutionErrorreturnscandidateCalls. OnKaMultiCallResolutionAttemptreturns the assembled multi-call when all sub-attempts succeeded; otherwise returns the combined calls from each sub-attempt.val KaCallResolutionAttempt.single: KaSimpleOrMultiCall?The only call of
calls, ornullwhen the attempt has no calls or more than one. Unlikesuccessful, it also answers for a failed resolution — the behavior of the legacyKaCallInfo.singleCallOrNull(). For a failedKaMultiCallResolutionAttemptthat entry may come from any sub-attempt, a resolved sub-call or a candidate of a failed one, so it is not necessarily a candidate for the element itself; for a successful one it is the assembledKaMultiCall, whose.simple/.function/.variablenarrowings arenull.val KaCallResolutionAttempt.successful: KaSimpleOrMultiCall?The resolved call if everything succeeded, otherwise
null. For a compound attempt this is the assembledKaMultiCallonly when every sub-attempt resolved.val KaCallResolutionAttempt.isSuccessful: BooleanWhether the resolution succeeded. Prefer this over a
this is KaSimpleCallResolutionSuccesscheck, which only covers simple attempts and silently treats a failedKaMultiCallResolutionAttemptas a success.val KaCallResolutionAttempt.errors: List<KaSimpleCallResolutionError>The errors of the attempt, for every attempt kind: empty on success, a one-element list for a simple error, and the failed sub-attempts of a multi-call attempt. The list is empty if and only if
isSuccessfulistrue, so this is the uniform way to get at the diagnostics of a failure.val KaCallResolutionAttempt.simpleAttempts: List<KaSimpleCallResolutionAttempt>The flattened sub-attempts: the attempt itself for a simple one, and
KaMultiCallResolutionAttempt.simpleAttemptsfor a compound one. Use it when the successful sub-calls of a partially failed compound matter, sinceerrorsdrops them.
For full control:
onSuccess is called with the resolved call when the attempt is a successful simple call or a fully successful multi-call. onFailure is called with the errors otherwise (a one-element list for a KaSimpleCallResolutionError, the failed sub-attempts for a partially-failed compound). The successful sub-attempts of a partially failed compound are not passed to onFailure; use simpleAttempts to reach them.