diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java
index 5aaa63ef117..9e36ad1550c 100644
--- a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java
+++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGenerated.java
@@ -82,6 +82,12 @@ public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGener
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
+ @Test
+ @TestMetadata("smartCastInAnonymousFunctionInWhenEntry.kt")
+ public void testSmartCastInAnonymousFunctionInWhenEntry() throws Exception {
+ runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt");
+ }
+
@Test
@TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception {
diff --git a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
index 6a29488a76b..4b32d64ac5c 100644
--- a/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
+++ b/analysis/analysis-api-fir/tests-gen/org/jetbrains/kotlin/analysis/api/fir/test/cases/generated/cases/components/scopeProvider/FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
@@ -82,6 +82,12 @@ public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerate
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
+ @Test
+ @TestMetadata("smartCastInAnonymousFunctionInWhenEntry.kt")
+ public void testSmartCastInAnonymousFunctionInWhenEntry() throws Exception {
+ runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt");
+ }
+
@Test
@TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception {
diff --git a/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/components/scopeProvider/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/components/scopeProvider/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
index 57cbc9a6486..ff714926347 100644
--- a/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/components/scopeProvider/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
+++ b/analysis/analysis-api-standalone/tests-gen/org/jetbrains/kotlin/analysis/api/standalone/fir/test/cases/generated/cases/components/scopeProvider/FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestGenerated.java
@@ -82,6 +82,12 @@ public class FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestG
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
+ @Test
+ @TestMetadata("smartCastInAnonymousFunctionInWhenEntry.kt")
+ public void testSmartCastInAnonymousFunctionInWhenEntry() throws Exception {
+ runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt");
+ }
+
@Test
@TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception {
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt
new file mode 100644
index 00000000000..4def2970f73
--- /dev/null
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.kt
@@ -0,0 +1,6 @@
+class A
+
+fun Any.test(): () -> Int = when {
+ this is A -> fun() = e
+ else -> { { 0 } }
+}
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt
new file mode 100644
index 00000000000..c7f50ce8179
--- /dev/null
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.pretty.txt
@@ -0,0 +1,79 @@
+element: e
+implicit receivers:
+ type: A
+ owner symbol: KtFirFunctionSymbol
+
+scopes:
+ LocalScope, index = 0
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 1
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 2
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 3
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ TypeScope, index = 4
+ packages: 0
+ classifiers: 0
+ callables: 3
+ fun equals(other: kotlin.Any?): kotlin.Boolean
+ fun hashCode(): kotlin.Int
+ fun toString(): kotlin.String
+ constructors: 1
+ constructor()
+
+ LocalScope, index = 5
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ ExplicitSimpleImportingScope, index = 6
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ PackageMemberScope, index = 7
+ packages: 6
+ META-INF
+ java
+ javax
+ kotlin
+ org
+ sun
+ classifiers: 1
+ class A
+ callables: 1
+ fun kotlin.Any.test(): () -> kotlin.Int
+ constructors: 0
+
+ DefaultSimpleImportingScope, index = 8
+
+ DefaultSimpleImportingScope, index = 9
+
+ ExplicitStarImportingScope, index = 10
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ DefaultSimpleImportingScope, index = 11
+
+ DefaultStarImportingScope, index = 12
diff --git a/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt
new file mode 100644
index 00000000000..ee79e2f3136
--- /dev/null
+++ b/analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunctionInWhenEntry.txt
@@ -0,0 +1,282 @@
+element: e
+implicit receivers:
+ type: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: A
+ owner symbol: KtFirFunctionSymbol
+
+scopes:
+ LocalScope, index = 0
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 1
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 2
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ LocalScope, index = 3
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ TypeScope, index = 4
+ packages: 0
+ classifiers: 0
+ callables: 3
+ KtFunctionSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: kotlin/Any.equals
+ contextReceivers: []
+ contractEffects: []
+ hasStableParameterNames: true
+ isActual: false
+ isBuiltinFunctionInvoke: false
+ isExpect: false
+ isExtension: false
+ isExternal: false
+ isInfix: false
+ isInline: false
+ isOperator: true
+ isOverride: false
+ isStatic: false
+ isSuspend: false
+ modality: OPEN
+ name: equals
+ origin: LIBRARY
+ receiverParameter: null
+ returnType: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Boolean
+ symbolKind: CLASS_MEMBER
+ typeParameters: []
+ valueParameters: [
+ KtValueParameterSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: null
+ contextReceivers: []
+ generatedPrimaryConstructorProperty: null
+ hasDefaultValue: false
+ isCrossinline: false
+ isExtension: false
+ isImplicitLambdaParameter: false
+ isNoinline: false
+ isVararg: false
+ name: other
+ origin: LIBRARY
+ receiverParameter: null
+ returnType: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Any?
+ symbolKind: LOCAL
+ typeParameters: []
+ ]
+ visibility: Public
+ KtFunctionSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: kotlin/Any.hashCode
+ contextReceivers: []
+ contractEffects: []
+ hasStableParameterNames: true
+ isActual: false
+ isBuiltinFunctionInvoke: false
+ isExpect: false
+ isExtension: false
+ isExternal: false
+ isInfix: false
+ isInline: false
+ isOperator: false
+ isOverride: false
+ isStatic: false
+ isSuspend: false
+ modality: OPEN
+ name: hashCode
+ origin: LIBRARY
+ receiverParameter: null
+ returnType: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Int
+ symbolKind: CLASS_MEMBER
+ typeParameters: []
+ valueParameters: []
+ visibility: Public
+ KtFunctionSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: kotlin/Any.toString
+ contextReceivers: []
+ contractEffects: []
+ hasStableParameterNames: true
+ isActual: false
+ isBuiltinFunctionInvoke: false
+ isExpect: false
+ isExtension: false
+ isExternal: false
+ isInfix: false
+ isInline: false
+ isOperator: false
+ isOverride: false
+ isStatic: false
+ isSuspend: false
+ modality: OPEN
+ name: toString
+ origin: LIBRARY
+ receiverParameter: null
+ returnType: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/String
+ symbolKind: CLASS_MEMBER
+ typeParameters: []
+ valueParameters: []
+ visibility: Public
+ constructors: 1
+ KtConstructorSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: null
+ containingClassIdIfNonLocal: A
+ contextReceivers: []
+ hasStableParameterNames: true
+ isActual: false
+ isExpect: false
+ isExtension: false
+ isPrimary: true
+ origin: SOURCE_MEMBER_GENERATED
+ receiverParameter: null
+ returnType: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: A
+ symbolKind: CLASS_MEMBER
+ typeParameters: []
+ valueParameters: []
+ visibility: Public
+
+ LocalScope, index = 5
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ ExplicitSimpleImportingScope, index = 6
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ PackageMemberScope, index = 7
+ packages: 6
+ KtPackageSymbol:
+ fqName: META-INF
+ origin: SOURCE
+ KtPackageSymbol:
+ fqName: java
+ origin: SOURCE
+ KtPackageSymbol:
+ fqName: javax
+ origin: SOURCE
+ KtPackageSymbol:
+ fqName: kotlin
+ origin: SOURCE
+ KtPackageSymbol:
+ fqName: org
+ origin: SOURCE
+ KtPackageSymbol:
+ fqName: sun
+ origin: SOURCE
+ classifiers: 1
+ KtNamedClassOrObjectSymbol:
+ annotationsList: []
+ classIdIfNonLocal: A
+ classKind: CLASS
+ companionObject: null
+ contextReceivers: []
+ isActual: false
+ isData: false
+ isExpect: false
+ isExternal: false
+ isFun: false
+ isInline: false
+ isInner: false
+ modality: FINAL
+ name: A
+ origin: SOURCE
+ superTypes: [
+ KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Any
+ ]
+ symbolKind: TOP_LEVEL
+ typeParameters: []
+ visibility: Public
+ callables: 1
+ KtFunctionSymbol:
+ annotationsList: []
+ callableIdIfNonLocal: /test
+ contextReceivers: []
+ contractEffects: []
+ hasStableParameterNames: true
+ isActual: false
+ isBuiltinFunctionInvoke: false
+ isExpect: false
+ isExtension: true
+ isExternal: false
+ isInfix: false
+ isInline: false
+ isOperator: false
+ isOverride: false
+ isStatic: false
+ isSuspend: false
+ modality: FINAL
+ name: test
+ origin: SOURCE
+ receiverParameter: KtReceiverParameterSymbol:
+ annotationsList: []
+ origin: SOURCE
+ owningCallableSymbol: KtFunctionSymbol(/test)
+ type: KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Any
+ returnType: KtFunctionalType:
+ annotationsList: []
+ ownTypeArguments: [
+ KtUsualClassType:
+ annotationsList: []
+ ownTypeArguments: []
+ type: kotlin/Int
+ ]
+ type: kotlin/Function0
+ symbolKind: TOP_LEVEL
+ typeParameters: []
+ valueParameters: []
+ visibility: Public
+ constructors: 0
+
+ DefaultSimpleImportingScope, index = 8
+
+ DefaultSimpleImportingScope, index = 9
+
+ ExplicitStarImportingScope, index = 10
+ packages: 0
+ classifiers: 0
+ callables: 0
+ constructors: 0
+
+ DefaultSimpleImportingScope, index = 11
+
+ DefaultStarImportingScope, index = 12
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt
index a3703ef34a9..4fbde6a755b 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt
@@ -666,16 +666,12 @@ open class FirDeclarationsResolveTransformer(
function: FirFunction,
data: ResolutionMode
): FirStatement = whileAnalysing(session, function) {
- val functionIsNotAnalyzed = !function.bodyResolved
- if (functionIsNotAnalyzed) {
- dataFlowAnalyzer.enterFunction(function)
- }
+ if (function.bodyResolved) return function
+ dataFlowAnalyzer.enterFunction(function)
return transformDeclarationContent(function, data).also {
- if (functionIsNotAnalyzed) {
- val result = it as FirFunction
- val controlFlowGraphReference = dataFlowAnalyzer.exitFunction(result)
- result.replaceControlFlowGraphReference(controlFlowGraphReference)
- }
+ val result = it as FirFunction
+ val controlFlowGraphReference = dataFlowAnalyzer.exitFunction(result)
+ result.replaceControlFlowGraphReference(controlFlowGraphReference)
} as FirStatement
}