diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt index a7525392058..c0c830eed1e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt @@ -8,6 +8,8 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerGroup import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.INAPPLICABLE_ARGUMENTS_MAPPING_ERROR +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER import org.jetbrains.kotlin.resolve.calls.tower.isSuccess import org.jetbrains.kotlin.resolve.calls.tower.shouldStopResolve @@ -51,7 +53,17 @@ open class CandidateCollector( bestGroup = group } - if (applicability == currentApplicability && group == bestGroup) { + /* + * Here we would like to consider error candidates with `INAPPLICABLE_WRONG_RECEIVER` and `INAPPLICABLE_ARGUMENTS_MAPPING_ERROR` kinda + * "same error level". Generally it's questionable which candidates we should keep and which of those applicabilities is more + * specific and we should consider it during work on improvement of error reporting. But this particular check is needed + * to fix the KT-65218, which provoked by different stdlib declarations order in CLI compilation mode and AA mode (see + * the issue for more details) + */ + if ( + (applicability == currentApplicability && group == bestGroup) || + (currentApplicability == INAPPLICABLE_ARGUMENTS_MAPPING_ERROR && applicability == INAPPLICABLE_WRONG_RECEIVER) + ) { candidates.add(candidate) } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt index a449ea3efd2..aa35269e61a 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/functionExpectedWhenSeveralInvokesExist.fir.kt @@ -8,6 +8,6 @@ class SomeClass fun test(identifier: SomeClass, fn: String.() -> Unit) { identifier() identifier(123) - identifier(1, 2) + identifier(1, 2) 1.fn() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt index 19c6f6a48d0..8bd66314281 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/unsafeAssignmentExtra.fir.txt @@ -60,7 +60,7 @@ FILE: unsafeAssignmentExtra.fir.kt } } - lval x: by this@R|special/anonymous|.R|SubstitutionOverride| + lval x: by this@R|special/anonymous|.R|SubstitutionOverride| this@R|special/anonymous|.R|/change|( = change@fun R|Foo|.(): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride| = Int(99) }