Fix KT-51478

The issue was that, when various context elements were available
to fulfill a need for an extension receiver, but none of them were
applicable to it, the compiler behaved the same way as if there
was no extension receiver at all.

https://youtrack.jetbrains.com/issue/KT-51478/Inapplicable-receiver-diagnostic-expected-when-there-are-two-context-receiver-candidates
This commit is contained in:
Dmitry Khalanskiy
2022-07-15 13:30:19 +02:00
committed by teamcity
parent dccb7faf2e
commit 4cbee3cde7
8 changed files with 57 additions and 2 deletions
@@ -704,7 +704,10 @@ internal object CheckReceivers : ResolutionPart() {
val extensionReceiverParameter = candidateDescriptor.extensionReceiverParameter ?: return null
val compatible = receiverCandidates.mapNotNull { getReceiverArgumentWithConstraintIfCompatible(it, extensionReceiverParameter) }
return when (compatible.size) {
0 -> null
0 -> {
addDiagnostic(NoMatchingContextReceiver())
null
}
1 -> compatible.single().argument
else -> {
addDiagnostic(ContextReceiverAmbiguity())
@@ -954,4 +957,4 @@ internal object CheckIncompatibleTypeVariableUpperBounds : ResolutionPart() {
}
}
}
}
}
@@ -114,6 +114,12 @@ abstract class ResolutionDiagnostic(candidateApplicability: CandidateApplicabili
}
}
class NoMatchingContextReceiver : ResolutionDiagnostic(INAPPLICABLE_WRONG_RECEIVER) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCall(this)
}
}
class ContextReceiverAmbiguity : ResolutionDiagnostic(RESOLVED_WITH_ERROR) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCall(this)