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:
committed by
teamcity
parent
dccb7faf2e
commit
4cbee3cde7
+6
@@ -11079,6 +11079,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("twoReceiverCandidatesError.kt")
|
||||||
|
public void testTwoReceiverCandidatesError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/twoReceiverCandidatesError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParameterAsContextReceiver.kt")
|
@TestMetadata("typeParameterAsContextReceiver.kt")
|
||||||
public void testTypeParameterAsContextReceiver() throws Exception {
|
public void testTypeParameterAsContextReceiver() throws Exception {
|
||||||
|
|||||||
+6
@@ -11079,6 +11079,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("twoReceiverCandidatesError.kt")
|
||||||
|
public void testTwoReceiverCandidatesError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/twoReceiverCandidatesError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParameterAsContextReceiver.kt")
|
@TestMetadata("typeParameterAsContextReceiver.kt")
|
||||||
public void testTypeParameterAsContextReceiver() throws Exception {
|
public void testTypeParameterAsContextReceiver() throws Exception {
|
||||||
|
|||||||
+6
@@ -11079,6 +11079,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("twoReceiverCandidatesError.kt")
|
||||||
|
public void testTwoReceiverCandidatesError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/twoReceiverCandidatesError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParameterAsContextReceiver.kt")
|
@TestMetadata("typeParameterAsContextReceiver.kt")
|
||||||
public void testTypeParameterAsContextReceiver() throws Exception {
|
public void testTypeParameterAsContextReceiver() throws Exception {
|
||||||
|
|||||||
+4
-1
@@ -704,7 +704,10 @@ internal object CheckReceivers : ResolutionPart() {
|
|||||||
val extensionReceiverParameter = candidateDescriptor.extensionReceiverParameter ?: return null
|
val extensionReceiverParameter = candidateDescriptor.extensionReceiverParameter ?: return null
|
||||||
val compatible = receiverCandidates.mapNotNull { getReceiverArgumentWithConstraintIfCompatible(it, extensionReceiverParameter) }
|
val compatible = receiverCandidates.mapNotNull { getReceiverArgumentWithConstraintIfCompatible(it, extensionReceiverParameter) }
|
||||||
return when (compatible.size) {
|
return when (compatible.size) {
|
||||||
0 -> null
|
0 -> {
|
||||||
|
addDiagnostic(NoMatchingContextReceiver())
|
||||||
|
null
|
||||||
|
}
|
||||||
1 -> compatible.single().argument
|
1 -> compatible.single().argument
|
||||||
else -> {
|
else -> {
|
||||||
addDiagnostic(ContextReceiverAmbiguity())
|
addDiagnostic(ContextReceiverAmbiguity())
|
||||||
|
|||||||
@@ -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) {
|
class ContextReceiverAmbiguity : ResolutionDiagnostic(RESOLVED_WITH_ERROR) {
|
||||||
override fun report(reporter: DiagnosticReporter) {
|
override fun report(reporter: DiagnosticReporter) {
|
||||||
reporter.onCall(this)
|
reporter.onCall(this)
|
||||||
|
|||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// !LANGUAGE: +ContextReceivers
|
||||||
|
// FIR_IDENTICAL
|
||||||
|
|
||||||
|
fun String.foo() {}
|
||||||
|
|
||||||
|
context(Int, Double)
|
||||||
|
fun bar() {
|
||||||
|
<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>foo<!>() // should be prohibited
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
with(1) {
|
||||||
|
with(2.0) {
|
||||||
|
bar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
context(kotlin.Int, kotlin.Double) public fun bar(): kotlin.Unit
|
||||||
|
public fun main(): kotlin.Unit
|
||||||
|
public fun kotlin.String.foo(): kotlin.Unit
|
||||||
Generated
+6
@@ -11085,6 +11085,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/thisWithReceiverLabelsProperties.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("twoReceiverCandidatesError.kt")
|
||||||
|
public void testTwoReceiverCandidatesError() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/extensions/contextReceivers/twoReceiverCandidatesError.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParameterAsContextReceiver.kt")
|
@TestMetadata("typeParameterAsContextReceiver.kt")
|
||||||
public void testTypeParameterAsContextReceiver() throws Exception {
|
public void testTypeParameterAsContextReceiver() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user