[FIR] Fix taking symbol of expression with smartcast inside DFA
This commit is contained in:
+5
@@ -2944,6 +2944,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
|||||||
public void testFunctionCallBound() throws Exception {
|
public void testFunctionCallBound() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
|
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")
|
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/smartcasts/controlStructures")
|
||||||
|
|||||||
Vendored
+14
@@ -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|()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
interface A {
|
||||||
|
fun foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Any.test() {
|
||||||
|
if (this is A) {
|
||||||
|
val a = this
|
||||||
|
a.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+6
@@ -3323,6 +3323,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
|||||||
public void testFunctionCallBound() throws Exception {
|
public void testFunctionCallBound() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
|
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
|
@Nested
|
||||||
|
|||||||
+6
@@ -3362,6 +3362,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
|||||||
public void testFunctionCallBound() throws Exception {
|
public void testFunctionCallBound() throws Exception {
|
||||||
runTest("compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
|
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
|
@Nested
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ internal val FirElement.symbol: AbstractFirBasedSymbol<*>?
|
|||||||
is FirWhenSubjectExpression -> whenRef.value.subject?.symbol
|
is FirWhenSubjectExpression -> whenRef.value.subject?.symbol
|
||||||
is FirSafeCallExpression -> regularQualifiedAccess.symbol
|
is FirSafeCallExpression -> regularQualifiedAccess.symbol
|
||||||
else -> null
|
else -> null
|
||||||
}?.takeIf { this is FirThisReceiverExpression || (it !is FirFunctionSymbol<*> && it !is FirAccessorSymbol) }
|
}?.takeIf { this.unwrapSmartcastExpression() is FirThisReceiverExpression || (it !is FirFunctionSymbol<*> && it !is FirAccessorSymbol) }
|
||||||
|
|
||||||
@DfaInternals
|
@DfaInternals
|
||||||
internal val FirResolvable.symbol: AbstractFirBasedSymbol<*>?
|
internal val FirResolvable.symbol: AbstractFirBasedSymbol<*>?
|
||||||
@@ -109,3 +109,5 @@ internal val FirResolvable.symbol: AbstractFirBasedSymbol<*>?
|
|||||||
is FirNamedReferenceWithCandidate -> reference.candidateSymbol
|
is FirNamedReferenceWithCandidate -> reference.candidateSymbol
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun FirElement.unwrapSmartcastExpression(): FirElement = if (this is FirExpressionWithSmartcast) originalExpression else this
|
||||||
|
|||||||
Reference in New Issue
Block a user