K2: Fix IAE at Candidate.updateSourcesOfReceivers inside PCLA lambda

Previously, it was failing at line
(resolvedReceiver?.toReference(session) as? FirNamedReferenceWithCandidate)?.candidate?.updateSourcesOfReceivers()

But this line was mostly incorrect because in case of `a.b()` call,
which is resolved to `a.b.invoke()`, `resolvedReceiver` is pointing to
`a` instead of obviously expected `a.b`.

The fix with using `candidate.callInfo.explicitReceiver` doesn't help
either because the candidate of that receiver is always completed at
that stage (so no Candidate there).

The only case when the candidate was still there is PCLA because
 in that case we explicitly don't fully complete even receiver
expressions.
(see docs/fir/pcla.md)

The idea of the fix is moving the call of `updateSourcesOfReceivers`
for invoke property receiver to the place just before the candidate
is being converted to the resolved reference
(i.e., the candidate is being lost)

^KT-66148 Fixed
This commit is contained in:
Denis.Zharkov
2024-03-05 15:43:10 +01:00
committed by Space Team
parent ae9c9b051f
commit b7129f78a3
30 changed files with 206 additions and 6 deletions
@@ -2631,6 +2631,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/builderInference/posptonedPCLACallInsideStringInterpolation.kt");
}
@Test
@TestMetadata("propertyInvokeInsidePCLALambda.kt")
public void testPropertyInvokeInsidePCLALambda() {
runTest("compiler/testData/codegen/box/builderInference/propertyInvokeInsidePCLALambda.kt");
}
@Test
@TestMetadata("receiverUsesOuterTVButReturnTypeIsProper.kt")
public void testReceiverUsesOuterTVButReturnTypeIsProper() {
@@ -2631,6 +2631,12 @@ public class FirJsES6CodegenBoxTestGenerated extends AbstractFirJsES6CodegenBoxT
runTest("compiler/testData/codegen/box/builderInference/posptonedPCLACallInsideStringInterpolation.kt");
}
@Test
@TestMetadata("propertyInvokeInsidePCLALambda.kt")
public void testPropertyInvokeInsidePCLALambda() {
runTest("compiler/testData/codegen/box/builderInference/propertyInvokeInsidePCLALambda.kt");
}
@Test
@TestMetadata("receiverUsesOuterTVButReturnTypeIsProper.kt")
public void testReceiverUsesOuterTVButReturnTypeIsProper() {
@@ -2631,6 +2631,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/builderInference/posptonedPCLACallInsideStringInterpolation.kt");
}
@Test
@TestMetadata("propertyInvokeInsidePCLALambda.kt")
public void testPropertyInvokeInsidePCLALambda() {
runTest("compiler/testData/codegen/box/builderInference/propertyInvokeInsidePCLALambda.kt");
}
@Test
@TestMetadata("receiverUsesOuterTVButReturnTypeIsProper.kt")
public void testReceiverUsesOuterTVButReturnTypeIsProper() {
@@ -2631,6 +2631,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
runTest("compiler/testData/codegen/box/builderInference/posptonedPCLACallInsideStringInterpolation.kt");
}
@Test
@TestMetadata("propertyInvokeInsidePCLALambda.kt")
public void testPropertyInvokeInsidePCLALambda() {
runTest("compiler/testData/codegen/box/builderInference/propertyInvokeInsidePCLALambda.kt");
}
@Test
@TestMetadata("receiverUsesOuterTVButReturnTypeIsProper.kt")
public void testReceiverUsesOuterTVButReturnTypeIsProper() {