[FIR] Fix resolving of refs with implicit this in lambdas in smartcasts

This commit is contained in:
Ivan Kochurkin
2022-03-20 20:17:00 +03:00
committed by teamcity
parent c6f52893fb
commit 48dbb9ceb9
8 changed files with 46 additions and 3 deletions
@@ -27932,6 +27932,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt");
}
@Test
@TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt")
public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt");
}
@Test
@TestMetadata("implicitToGrandSon.kt")
public void testImplicitToGrandSon() throws Exception {
@@ -27932,6 +27932,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt");
}
@Test
@TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt")
public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt");
}
@Test
@TestMetadata("implicitToGrandSon.kt")
public void testImplicitToGrandSon() throws Exception {
@@ -27932,6 +27932,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt");
}
@Test
@TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt")
public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt");
}
@Test
@TestMetadata("implicitToGrandSon.kt")
public void testImplicitToGrandSon() throws Exception {
@@ -105,14 +105,15 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
val index = receiverStack.getReceiverIndex(symbol) ?: return
val info = flow.getTypeStatement(variable)
if (info == null) {
receiverStack.replaceReceiverType(index, receiverStack.getOriginalType(index))
val type = if (info == null) {
receiverStack.getOriginalType(index)
} else {
val types = info.exactType.toMutableList().also {
it += receiverStack.getOriginalType(index)
}
receiverStack.replaceReceiverType(index, context.intersectTypesOrNull(types)!!)
context.intersectTypesOrNull(types)!!
}
receiverStack.replaceReceiverType(index, type)
}
override fun updateAllReceivers(flow: PersistentFlow) {
@@ -282,6 +283,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
// TODO: questionable
postponedLambdaEnterNode?.mergeIncomingFlow()
functionEnterNode.mergeIncomingFlow()
logicSystem.updateAllReceivers(functionEnterNode.flow)
}
private fun exitAnonymousFunction(anonymousFunction: FirAnonymousFunction): FirControlFlowGraphReference {
@@ -0,0 +1,7 @@
fun Any.test() {
val x: () -> Int = when (this) {
is String -> { { length } }
else -> { { 1 } }
}
<!UNRESOLVED_REFERENCE!>length<!>
}
@@ -0,0 +1,7 @@
fun Any.test() {
val x: () -> Int = when (this) {
is String -> { { <!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>length<!> } }
else -> { { 1 } }
}
<!UNRESOLVED_REFERENCE!>length<!>
}
@@ -0,0 +1,3 @@
package
public fun kotlin.Any.test(): kotlin.Unit
@@ -28022,6 +28022,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitReceiver.kt");
}
@Test
@TestMetadata("implicitThisOnRefInLambdaInSmartcast.kt")
public void testImplicitThisOnRefInLambdaInSmartcast() throws Exception {
runTest("compiler/testData/diagnostics/tests/smartCasts/implicitThisOnRefInLambdaInSmartcast.kt");
}
@Test
@TestMetadata("implicitToGrandSon.kt")
public void testImplicitToGrandSon() throws Exception {