[FIR] Fix taking symbol of expression with smartcast inside DFA

This commit is contained in:
Dmitriy Novozhilov
2021-02-17 17:38:23 +03:00
parent adb05ab076
commit 9b4949a3c5
6 changed files with 46 additions and 1 deletions
@@ -2944,6 +2944,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
public void testFunctionCallBound() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
}
@TestMetadata("thisAssignment.kt")
public void testThisAssignment() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/thisAssignment.kt");
}
}
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures")
@@ -0,0 +1,14 @@
FILE: thisAssignment.kt
public abstract interface A : R|kotlin/Any| {
public abstract fun foo(): R|kotlin/Unit|
}
public final fun R|kotlin/Any|.test(): R|kotlin/Unit| {
when () {
(this@R|/test| is R|A|) -> {
lval a: R|kotlin/Any| = this@R|/test|
R|<local>/a|.R|/A.foo|()
}
}
}
@@ -0,0 +1,12 @@
interface A {
fun foo()
}
fun Any.test() {
if (this is A) {
val a = this
a.foo()
}
}
@@ -3323,6 +3323,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
public void testFunctionCallBound() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
}
@Test
@TestMetadata("thisAssignment.kt")
public void testThisAssignment() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/thisAssignment.kt");
}
}
@Nested
@@ -3362,6 +3362,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
public void testFunctionCallBound() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
}
@Test
@TestMetadata("thisAssignment.kt")
public void testThisAssignment() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/thisAssignment.kt");
}
}
@Nested
@@ -99,7 +99,7 @@ internal val FirElement.symbol: AbstractFirBasedSymbol<*>?
is FirWhenSubjectExpression -> whenRef.value.subject?.symbol
is FirSafeCallExpression -> regularQualifiedAccess.symbol
else -> null
}?.takeIf { this is FirThisReceiverExpression || (it !is FirFunctionSymbol<*> && it !is FirAccessorSymbol) }
}?.takeIf { this.unwrapSmartcastExpression() is FirThisReceiverExpression || (it !is FirFunctionSymbol<*> && it !is FirAccessorSymbol) }
@DfaInternals
internal val FirResolvable.symbol: AbstractFirBasedSymbol<*>?
@@ -109,3 +109,5 @@ internal val FirResolvable.symbol: AbstractFirBasedSymbol<*>?
is FirNamedReferenceWithCandidate -> reference.candidateSymbol
else -> null
}
private fun FirElement.unwrapSmartcastExpression(): FirElement = if (this is FirExpressionWithSmartcast) originalExpression else this