FIR IDE: collect snapshot of FirTowerDataContext for statements
ImplicitReceiverValue is mutable and FIR body resolve could alter it
while analysing code with smartcast. Hence, previously the IDE may see
inconsistent receiver values for a local scope. For example
```
open class A
interface Foo {
fun foo()
}
fun A.bar() {
if (this is Foo) {
// scope here has implicit receiver type to be `A` rather than `it<A, Foo>`
}
}
```
This change creates snapshots for local statements so later changes
during body resolve won't affect the collected context.
This commit is contained in:
committed by
Ilya Kirillov
parent
aad02c1259
commit
e5b9d667c0
+2
-1
@@ -37,7 +37,8 @@ internal class FirTowerDataContextAllElementsCollector : FirTowerDataContextColl
|
||||
|
||||
override fun addStatementContext(statement: FirStatement, context: FirTowerDataContext) {
|
||||
val closestStatementInBlock = statement.psi?.closestBlockLevelOrInitializerExpression() ?: return
|
||||
elementsToContext[closestStatementInBlock] = context
|
||||
// FIR body transform may alter the context if there are implicit receivers with smartcast
|
||||
elementsToContext[closestStatementInBlock] = context.createSnapshot()
|
||||
}
|
||||
|
||||
override fun addDeclarationContext(declaration: FirDeclaration, context: FirTowerDataContext) {
|
||||
|
||||
Reference in New Issue
Block a user