[Analysis API] Introduce 'possibleSmartCasts' in 'KaScopeContext'

The new endpoint makes it possible to track potential smart casts in a
particular position, even if a real cast isn't yet present in the
source code.

^KT-84255 Fixed
diff --git a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KaFe10ScopeProvider.kt b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KaFe10ScopeProvider.kt
index 396980b..b528648 100644
--- a/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KaFe10ScopeProvider.kt
+++ b/analysis/analysis-api-fe10/src/org/jetbrains/kotlin/analysis/api/descriptors/components/KaFe10ScopeProvider.kt
@@ -233,8 +233,9 @@
         if (lexicalScope != null) {
             val compositeScope = KaBaseCompositeScope.create(listOf(KaFe10ScopeLexical(lexicalScope, analysisContext)), token)
             return KaBaseScopeContext(
-                listOf(KaScopeWithKindImpl(compositeScope, scopeKind)),
-                collectImplicitReceivers(lexicalScope),
+                scopes = listOf(KaScopeWithKindImpl(compositeScope, scopeKind)),
+                implicitValues = collectImplicitReceivers(lexicalScope),
+                possibleSmartCasts = listOf(),
                 token,
             )
         }
@@ -242,8 +243,9 @@
         val fileScope = analysisContext.resolveSession.fileScopeProvider.getFileResolutionScope(this)
         val compositeScope = KaBaseCompositeScope.create(listOf(KaFe10ScopeLexical(fileScope, analysisContext)), token)
         return KaBaseScopeContext(
-            listOf(KaScopeWithKindImpl(compositeScope, scopeKind)),
-            collectImplicitReceivers(fileScope),
+            scopes = listOf(KaScopeWithKindImpl(compositeScope, scopeKind)),
+            implicitValues = collectImplicitReceivers(fileScope),
+            possibleSmartCasts = emptyList(),
             token,
         )
     }
@@ -253,7 +255,13 @@
             val importingScopes = scopeContext(position = this)
                 .scopes
                 .filter { it.kind is KaScopeKind.ImportingScope }
-            return KaBaseScopeContext(importingScopes, implicitValues = emptyList(), token)
+
+            return KaBaseScopeContext(
+                scopes = importingScopes,
+                implicitValues = emptyList(),
+                possibleSmartCasts = emptyList(),
+                token
+            )
         }
 
     private inline fun <reified T : DeclarationDescriptor> getDescriptor(symbol: KaSymbol): T? {
diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KaFirScopeProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KaFirScopeProvider.kt
index 8b6e711..45bfcf6 100644
--- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KaFirScopeProvider.kt
+++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KaFirScopeProvider.kt
@@ -19,8 +19,10 @@
 import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
 import org.jetbrains.kotlin.analysis.api.scopes.KaScope
 import org.jetbrains.kotlin.analysis.api.scopes.KaTypeScope
+import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaFileSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaPackageSymbol
+import org.jetbrains.kotlin.analysis.api.symbols.KaVariableSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.markers.KaDeclarationContainerSymbol
 import org.jetbrains.kotlin.analysis.api.types.KaType
 import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirFile
@@ -37,6 +39,7 @@
 import org.jetbrains.kotlin.fir.resolve.ScopeSession
 import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertiesScope
 import org.jetbrains.kotlin.fir.resolve.calls.referencedMemberSymbol
+import org.jetbrains.kotlin.fir.resolve.dfa.RealVariable
 import org.jetbrains.kotlin.fir.resolve.scope
 import org.jetbrains.kotlin.fir.resolve.scopeSessionKey
 import org.jetbrains.kotlin.fir.scopes.*
@@ -50,6 +53,7 @@
 import org.jetbrains.kotlin.name.Name
 import org.jetbrains.kotlin.psi.KtElement
 import org.jetbrains.kotlin.psi.KtFile
+import org.jetbrains.kotlin.types.SmartcastStability
 import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
 import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
 
@@ -280,7 +284,13 @@
             val firImportingScopesIndexed = firImportingScopes.asReversed().withIndex()
 
             val ktScopesWithKinds = createScopesWithKind(firImportingScopesIndexed)
-            return KaBaseScopeContext(ktScopesWithKinds, implicitValues = emptyList(), token)
+
+            return KaBaseScopeContext(
+                scopes = ktScopesWithKinds,
+                implicitValues = emptyList(),
+                possibleSmartCasts = emptyList(),
+                token
+            )
         }
 
     // Do not check [this] psi validity as it is not used
@@ -336,9 +346,36 @@
                 .flatMap { flattenFirScope(it) }
             availableScopes.map { IndexedValue(index, it) }
         }
-        val ktScopesWithKinds = createScopesWithKind(firScopes)
 
-        return KaBaseScopeContext(ktScopesWithKinds, implicitValues, token)
+        return KaBaseScopeContext(
+            scopes = createScopesWithKind(firScopes),
+            implicitValues = implicitValues,
+            possibleSmartCasts = computeSmartCastPossibilities(context),
+            token = token
+        )
+    }
+
+    private fun computeSmartCastPossibilities(context: ContextCollector.Context): List<KaSmartCastPossibility> {
+        return context.smartCasts.mapNotNull { smartCast ->
+            val source = computeSmartCastSource(smartCast.realVariable)
+                ?.takeIf { it.symbol is KaVariableSymbol } ?: return@mapNotNull null
+
+            KaBaseSmartCastPossibility(
+                source = @Suppress("UNCHECKED_CAST") (source as KaSmartCastSource<KaVariableSymbol>),
+                resultingTypes = smartCast.upperTypes.map { firSymbolBuilder.typeBuilder.buildKtType(it) },
+                isStable = smartCast.stability == SmartcastStability.STABLE_VALUE
+            )
+        }
+    }
+
+    private fun computeSmartCastSource(realVariable: RealVariable): KaSmartCastSource<KaDeclarationSymbol>? {
+        val symbol = firSymbolBuilder.buildSymbol(realVariable.symbol) as? KaDeclarationSymbol ?: return null
+        return KaBaseSmartCastSource(
+            symbol = symbol,
+            dispatchReceiver = realVariable.dispatchReceiver?.let(::computeSmartCastSource),
+            extensionReceiver = realVariable.extensionReceiver?.let(::computeSmartCastSource),
+            type = firSymbolBuilder.typeBuilder.buildKtType(realVariable.originalType),
+        )
     }
 
     private fun createScopesWithKind(firScopes: Iterable<IndexedValue<FirScope>>): List<KaScopeWithKind> {
diff --git a/analysis/analysis-api-impl-base/src/org/jetbrains/kotlin/analysis/api/impl/base/components/KaBaseScopeProvider.kt b/analysis/analysis-api-impl-base/src/org/jetbrains/kotlin/analysis/api/impl/base/components/KaBaseScopeProvider.kt
index 6fe3ba7..22491a6 100644
--- a/analysis/analysis-api-impl-base/src/org/jetbrains/kotlin/analysis/api/impl/base/components/KaBaseScopeProvider.kt
+++ b/analysis/analysis-api-impl-base/src/org/jetbrains/kotlin/analysis/api/impl/base/components/KaBaseScopeProvider.kt
@@ -10,20 +10,62 @@
 import org.jetbrains.kotlin.analysis.api.lifetime.KaLifetimeToken
 import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
 import org.jetbrains.kotlin.analysis.api.symbols.KaContextParameterSymbol
+import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
+import org.jetbrains.kotlin.analysis.api.symbols.KaVariableSymbol
 import org.jetbrains.kotlin.analysis.api.types.KaType
 
 @KaImplementationDetail
 class KaBaseScopeContext(
     scopes: List<KaScopeWithKind>,
     implicitValues: List<KaScopeImplicitValue>,
+    possibleSmartCasts: List<KaSmartCastPossibility>,
     override val token: KaLifetimeToken,
 ) : KaScopeContext {
     private val backingImplicitValues: List<KaScopeImplicitValue> = implicitValues
     private val backingScopes: List<KaScopeWithKind> = scopes
+    private val backingPossibleSmartCasts: List<KaSmartCastPossibility> = possibleSmartCasts
 
     override val implicitValues: List<KaScopeImplicitValue> get() = withValidityAssertion { backingImplicitValues }
     override val scopes: List<KaScopeWithKind> get() = withValidityAssertion { backingScopes }
+    override val possibleSmartCasts: List<KaSmartCastPossibility> get() = withValidityAssertion { backingPossibleSmartCasts }
+}
+
+@KaImplementationDetail
+class KaBaseSmartCastPossibility(
+    source: KaSmartCastSource<KaVariableSymbol>,
+    resultingTypes: List<KaType>,
+    isStable: Boolean
+) : KaSmartCastPossibility {
+    private val backingSource: KaSmartCastSource<KaVariableSymbol> = source
+    private val backingResultingTypes: List<KaType> = resultingTypes
+    private val backingIsStable: Boolean = isStable
+
+    override val token: KaLifetimeToken get() = backingSource.token
+
+    override val source: KaSmartCastSource<KaVariableSymbol> get() = withValidityAssertion { backingSource }
+    override val resultingTypes: List<KaType> get() = withValidityAssertion { backingResultingTypes }
+    override val isStable: Boolean get() = withValidityAssertion { backingIsStable }
+}
+
+@KaImplementationDetail
+class KaBaseSmartCastSource<T : KaDeclarationSymbol>(
+    symbol: T,
+    dispatchReceiver: KaSmartCastSource<KaDeclarationSymbol>?,
+    extensionReceiver: KaSmartCastSource<KaDeclarationSymbol>?,
+    type: KaType,
+) : KaSmartCastSource<T> {
+    private val backingSymbol: T = symbol
+    private val backingDispatchReceiver: KaSmartCastSource<KaDeclarationSymbol>? = dispatchReceiver
+    private val backingExtensionReceiver: KaSmartCastSource<KaDeclarationSymbol>? = extensionReceiver
+    private val backingType: KaType = type
+
+    override val token: KaLifetimeToken get() = backingSymbol.token
+
+    override val symbol: T get() = withValidityAssertion { backingSymbol }
+    override val dispatchReceiver: KaSmartCastSource<KaDeclarationSymbol>? get() = withValidityAssertion { backingDispatchReceiver }
+    override val extensionReceiver: KaSmartCastSource<KaDeclarationSymbol>? get() = withValidityAssertion { backingExtensionReceiver }
+    override val type: KaType get() = withValidityAssertion { backingType }
 }
 
 @KaImplementationDetail
diff --git a/analysis/analysis-api-impl-base/testFixtures/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/scopeProvider/TestScopeRenderer.kt b/analysis/analysis-api-impl-base/testFixtures/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/scopeProvider/TestScopeRenderer.kt
index 9b85dd5..8d8cc2f 100644
--- a/analysis/analysis-api-impl-base/testFixtures/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/scopeProvider/TestScopeRenderer.kt
+++ b/analysis/analysis-api-impl-base/testFixtures/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/components/scopeProvider/TestScopeRenderer.kt
@@ -61,11 +61,43 @@
                 withIndent {
                     renderScopeContext(scopeContext, printer, printPretty, fullyPrintScope)
                 }
+
+                if (scopeContext.possibleSmartCasts.isNotEmpty()) {
+                    appendLine("possible smart casts:")
+                    withIndent {
+                        printCollection(scopeContext.possibleSmartCasts, separator = "\n\n") { smartCast ->
+                            appendSmartCastSource(KaSmartCastPossibility::source.name, smartCast.source, printer)
+                            append(KaSmartCastPossibility::isStable.name).append(" = ").append(smartCast.isStable.toString()).appendLine()
+                            append(KaSmartCastPossibility::resultingTypes.name).appendLine(":")
+                            printCollection(smartCast.resultingTypes, separator = "\n") { type ->
+                                withIndent {
+                                    append(renderType(type, printPretty))
+                                }
+                            }
+                        }
+                    }
+                }
             }
         }
     }
 
     context(_: KaSession)
+    private fun appendSmartCastSource(propertyName: String, source: KaSmartCastSource<*>, printer: PrettyPrinter): Unit = with(printer) {
+        append(propertyName).appendLine(":")
+        withIndent {
+            appendSymbol("symbol", printer, source.symbol)
+            appendLine()
+            source.dispatchReceiver?.let { dispatchReceiver ->
+                withIndent { appendSmartCastSource(KaSmartCastSource<*>::dispatchReceiver.name, dispatchReceiver, printer) }
+            }
+            source.extensionReceiver?.let { extensionReceiver ->
+                withIndent { appendSmartCastSource(KaSmartCastSource<*>::extensionReceiver.name, extensionReceiver, printer) }
+            }
+            append("type = ").append(renderType(source.type, printPretty = true)).appendLine()
+        }
+    }
+
+    context(_: KaSession)
     private fun appendSymbol(propertyName: String, printer: PrettyPrinter, symbol: KaSymbol): Unit = with(printer) {
         appendLine("$propertyName = ${renderFrontendIndependentKClassNameOf(symbol)}:")
         withIndent {
diff --git a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaScopeProvider.kt b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaScopeProvider.kt
index e998dca..824fc44 100644
--- a/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaScopeProvider.kt
+++ b/analysis/analysis-api/src/org/jetbrains/kotlin/analysis/api/components/KaScopeProvider.kt
@@ -12,9 +12,11 @@
 import org.jetbrains.kotlin.analysis.api.scopes.KaScope
 import org.jetbrains.kotlin.analysis.api.scopes.KaTypeScope
 import org.jetbrains.kotlin.analysis.api.symbols.KaContextParameterSymbol
+import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaFileSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaPackageSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.KaSymbol
+import org.jetbrains.kotlin.analysis.api.symbols.KaVariableSymbol
 import org.jetbrains.kotlin.analysis.api.symbols.markers.KaDeclarationContainerSymbol
 import org.jetbrains.kotlin.analysis.api.types.KaType
 import org.jetbrains.kotlin.psi.KtElement
@@ -297,6 +299,125 @@
      * The list is sorted according to the order of scopes in the scope tower (from innermost to outermost).
      */
     public val scopes: List<KaScopeWithKind>
+
+    /**
+     * The list of smart casts available at the context position.
+     *
+     * Note that the actual smart cast will only appear if the original expression type does not match the expected type.
+     * For actual smart cast application, check [KaDataFlowProvider.smartCastInfo].
+     *
+     * The list has an arbitrary (but stable) order.
+     */
+    @KaK1Unsupported
+    @KaExperimentalApi
+    public val possibleSmartCasts: List<KaSmartCastPossibility>
+}
+
+/**
+ * Represents a possible smart cast at a fixed context position.
+ *
+ * The word "possible" means that the compiler is allowed to produce smart casts for the [source] expression if there is a need to do so.
+ * Note that unless [isStable] is set, the smart cast will not be applied. In addition, the `SMARTCAST_IMPOSSIBLE` error is issued
+ * in certain cases.
+ */
+@KaExperimentalApi
+public interface KaSmartCastPossibility : KaLifetimeOwner {
+    /**
+     * A declaration, references to which smart cast may be applied (if [isStable] is `true`).
+     */
+    public val source: KaSmartCastSource<KaVariableSymbol>
+
+    /**
+     * Types that [source] may be automatically cast to.
+     */
+    public val resultingTypes: List<KaType>
+
+    /**
+     * Whether the smart cast [source] is stable at the context position.
+     *
+     * The same [source] can have different smart cast stability depending on the context position.
+     * Such as, in the code snippet below, a smart cast will be applied to the first usage of `value`. However, after the conditional
+     * expression, the compiler is not sure anymore that the `value` is still set, so a compilation error is reported.
+     *
+     * ```
+     * fun test() {
+     *     var value: String? = System.getProperty("some.property")
+     *     if (value == null) {
+     *         return
+     *     }
+     *
+     *     value.length  // Smart cast is applied
+     *
+     *     if (Random.nextBoolean()) {
+     *         value = null
+     *     }
+     *
+     *     value.length  // UNSAFE_CALL
+     * }
+     * ```
+     *
+     * For more information on the smart cast stability, check the Kotlin specification:
+     * [Smart cast sink stability](https://kotlinlang.org/spec/type-inference.html#smart-cast-sink-stability).
+     */
+    public val isStable: Boolean
+}
+
+/**
+ * Either a symbol for which a smart cast is generated, or one of its receivers.
+ */
+@KaExperimentalApi
+public interface KaSmartCastSource<T : KaDeclarationSymbol> : KaLifetimeOwner {
+    /**
+     * A declaration participating in the smart cast path.
+     *
+     * Smart casts to the same declaration can be allowed or prohibited, depending on how that declaration is accessed.
+     * In the following example, the [symbol] will be `val value: Any`. However, only for `a.value` a smart cast will be produced.
+     *
+     * ```
+     * class Holder(val value: Any)
+     *
+     * fun test(a: Holder, b: Holder) {
+     *     if (a.value is String) {
+     *         a.value.length  // OK
+     *         b.value.length  // compilation error
+     *     }
+     * }
+     * ```
+     *
+     * For `a.value` from the example above, a [KaSmartCastSource] is generated, [symbol] of which points to `val value: Any` (a property),
+     * and the [dispatchReceiver] will be the `a: Holder` value parameter.
+     */
+    public val symbol: T
+
+    /**
+     * The required dispatch receiver for this path component, if any.
+     *
+     * The [symbol] only participates in the smart cast if its dispatch receiver is the same as this one. E.g.:
+     *
+     * ```
+     * class Holder(val value: Any)
+     *
+     * fun test(holder: Holder) {
+     *     if (holder.value is String) {
+     *         holder.value.legnth  // Context position
+     *     }
+     * }
+     * ```
+     *
+     * In the example above, the `holder` parameter is a required dispatch receiver for `value`. If any other receiver is passed,
+     * such as `Holder().value`, the smart cast is not generated.
+     */
+    public val dispatchReceiver: KaSmartCastSource<KaDeclarationSymbol>?
+
+    /**
+     * The required extension receiver for this path component, if any.
+     */
+    public val extensionReceiver: KaSmartCastSource<KaDeclarationSymbol>?
+
+    /**
+     * The original type of the [symbol].
+     */
+    public val type: KaType
 }
 
 /**
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.pretty.txt
index 3a7fa61..34ddfa4 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.pretty.txt
@@ -143,3 +143,13 @@
 
   DefaultStarImportingScope, index = 18
 
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      a: T
+    type = T
+  isStable = true
+  resultingTypes:
+    BaseA
+    kotlin.Any
+    A
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.txt
index 032b24f..e4d23f3 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameter.txt
@@ -985,3 +985,23 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 18
+
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      a: T
+    type = T
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: BaseA
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: A
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.pretty.txt
index 8c65116..bc49af6 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.pretty.txt
@@ -75,3 +75,12 @@
 
   DefaultStarImportingScope, index = 10
 
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      a: T
+    type = T
+  isStable = true
+  resultingTypes:
+    BaseA
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.txt
index 81eeb15..f4486f4 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/nestedContextParameterAfter.txt
@@ -622,3 +622,19 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 10
+
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      a: T
+    type = T
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: BaseA
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.pretty.txt
index 999a155..42ad870 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.pretty.txt
@@ -62,3 +62,12 @@
 
   DefaultStarImportingScope, index = 9
 
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      c: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.Int
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.txt
index 1745f1e..9a7579c 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastFunction.txt
@@ -302,3 +302,19 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 9
+
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      c: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Int
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.pretty.txt
index 4d4a56c..4476720 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.pretty.txt
@@ -62,3 +62,12 @@
 
   DefaultStarImportingScope, index = 9
 
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      c: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.Int
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.txt
index 55f7177..f854a85 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/contextParameters/smartCastProperty.txt
@@ -294,3 +294,18 @@
 
   DefaultStarImportingScope, index = 9
 
+possible smart casts:
+  source:
+    symbol = KaContextParameterSymbol:
+      c: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Int
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt
index 47862a0..dcfe769 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.pretty.txt
@@ -166,3 +166,11 @@
 
   DefaultStarImportingScope, index = 19
 
+possible smart casts:
+  source:
+    symbol = KaValueParameterSymbol:
+      param: kotlin.String?
+    type = kotlin.String?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt
index 803bddd..541b781 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.txt
@@ -1328,3 +1328,15 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 19
+
+possible smart casts:
+  source:
+    symbol = KaValueParameterSymbol:
+      param: kotlin.String?
+    type = kotlin.String?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.pretty.txt
index a643257..729ab0f 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.pretty.txt
@@ -79,3 +79,32 @@
 
   DefaultStarImportingScope, index = 11
 
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    A
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.txt
index bfebf26..165024c 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.txt
@@ -323,3 +323,39 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 11
+
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: A
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt
index a643257..729ab0f 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt
@@ -79,3 +79,32 @@
 
   DefaultStarImportingScope, index = 11
 
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    A
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt
index bfebf26..165024c 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt
@@ -323,3 +323,39 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 11
+
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: A
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.pretty.txt
index 1d7a576..a9f94e2 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.pretty.txt
@@ -62,3 +62,32 @@
 
   DefaultStarImportingScope, index = 8
 
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    A
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.txt
index 17e2212..48a97e7 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInWhenEntryCondition.txt
@@ -326,3 +326,39 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 8
+
+possible smart casts:
+  source:
+    symbol = KaReceiverParameterSymbol:
+      KaReceiverParameterSymbol:
+        annotations: []
+        callableId: null
+        compilerVisibility: Public
+        contextReceivers: []
+        isActual: false
+        isExpect: false
+        isExtension: false
+        isExternal: false
+        isVal: true
+        location: LOCAL
+        modality: FINAL
+        name: <receiver>
+        origin: SOURCE
+        owningCallableSymbol: KaNamedFunctionSymbol(/test)
+        receiverParameter: null
+        returnType: KaUsualClassType:
+          annotations: []
+          typeArguments: []
+          type: kotlin/Any
+        visibility: PUBLIC
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: A
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.pretty.txt
index 12e5f33..89a0857 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.pretty.txt
@@ -51,3 +51,22 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 8
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      val a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Int
+    kotlin.Any
+
+  source:
+    symbol = KaLocalVariableSymbol:
+      val b: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Int
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.txt
index ddce69c..e4cc079 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/bound.txt
@@ -140,3 +140,34 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 8
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      val a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Int
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+
+  source:
+    symbol = KaLocalVariableSymbol:
+      val b: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Int
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.pretty.txt
index beea19f..52a5c79d 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.pretty.txt
@@ -45,3 +45,12 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.txt
index 29d2e14..bab007a 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/breakFromInfiniteLoop.txt
@@ -145,3 +145,15 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.pretty.txt
index beea19f..52a5c79d 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.pretty.txt
@@ -45,3 +45,12 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.txt
index 29d2e14..bab007a 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile.txt
@@ -145,3 +145,15 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.pretty.txt
index 80ecac5..48b3338 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.pretty.txt
@@ -45,3 +45,12 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.txt
index cf2d430..dbe457b 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/doWhile2.txt
@@ -173,3 +173,15 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.pretty.txt
index 020d683..df819da 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.pretty.txt
@@ -44,3 +44,13 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      val p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.String
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.txt
index 3ced2c3..6a7e765 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariable.txt
@@ -113,3 +113,19 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      val p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/String
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.pretty.txt
index 26ab1a6..5ca1192 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.pretty.txt
@@ -44,3 +44,13 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.String
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.txt
index 6d0b6f9..f54f665 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/localVariableMutable.txt
@@ -113,3 +113,19 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/String
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.pretty.txt
index 1106dfa..f2d5486 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.pretty.txt
@@ -45,3 +45,20 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
+
+  source:
+    symbol = KaLocalVariableSymbol:
+      var c: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.txt
index 9eb2541..99c3939 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/noSmartCastInInference.txt
@@ -134,3 +134,26 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+
+  source:
+    symbol = KaLocalVariableSymbol:
+      var c: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.pretty.txt
index be27efa..f0c774ca 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.pretty.txt
@@ -44,3 +44,13 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaValueParameterSymbol:
+      p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.String
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.txt
index 2e3108d..520f5f3 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/parameterSimple.txt
@@ -147,3 +147,19 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaValueParameterSymbol:
+      p: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/String
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.pretty.txt
index a523cfd..66894d1 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.pretty.txt
@@ -57,3 +57,26 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 9
+
+possible smart casts:
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val a: kotlin.Any
+      dispatchReceiver:
+        symbol = KaValueParameterSymbol:
+          foo: kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.String
+    kotlin.Any
+
+  source:
+    symbol = KaValueParameterSymbol:
+      foo: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    Foo
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.txt
index e227082..7e2429d 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReference.txt
@@ -185,3 +185,38 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 9
+
+possible smart casts:
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val a: kotlin.Any
+      dispatchReceiver:
+        symbol = KaValueParameterSymbol:
+          foo: kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/String
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+
+  source:
+    symbol = KaValueParameterSymbol:
+      foo: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: Foo
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.pretty.txt
index f5aea0f..de9acca 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.pretty.txt
@@ -64,3 +64,43 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 10
+
+possible smart casts:
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val a: kotlin.Any
+      dispatchReceiver:
+        symbol = KaValueParameterSymbol:
+          foo: kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    Bar
+    kotlin.Any
+
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val b: kotlin.Any
+      dispatchReceiver:
+        symbol = KaKotlinPropertySymbol:
+          val a: kotlin.Any
+          dispatchReceiver:
+            symbol = KaValueParameterSymbol:
+              foo: kotlin.Any
+            type = kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    kotlin.String
+    kotlin.Any
+
+  source:
+    symbol = KaValueParameterSymbol:
+      foo: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    Foo
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.txt
index 1c26c2e..6b0e3ee 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/qualifiedReferenceNested.txt
@@ -217,3 +217,61 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 10
+
+possible smart casts:
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val a: kotlin.Any
+      dispatchReceiver:
+        symbol = KaValueParameterSymbol:
+          foo: kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: Bar
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+
+  source:
+    symbol = KaKotlinPropertySymbol:
+      val b: kotlin.Any
+      dispatchReceiver:
+        symbol = KaKotlinPropertySymbol:
+          val a: kotlin.Any
+          dispatchReceiver:
+            symbol = KaValueParameterSymbol:
+              foo: kotlin.Any
+            type = kotlin.Any
+        type = kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/String
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
+
+  source:
+    symbol = KaValueParameterSymbol:
+      foo: kotlin.Any
+    type = kotlin.Any
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: Foo
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.pretty.txt
index 17dc9c3..964cb19 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.pretty.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.pretty.txt
@@ -46,3 +46,12 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    kotlin.Any
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.txt
index 3d5ef20..6392670 100644
--- a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.txt
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCasts/smartCastInInference.txt
@@ -207,3 +207,15 @@
     constructors: 0
 
   DefaultStarImportingScope, index = 7
+
+possible smart casts:
+  source:
+    symbol = KaLocalVariableSymbol:
+      var a: kotlin.Any?
+    type = kotlin.Any?
+  isStable = true
+  resultingTypes:
+    KaUsualClassType:
+      annotations: []
+      typeArguments: []
+      type: kotlin/Any