[FIR] don't transform analyzed lambda
Inside `transformDeclarationContent` current tower data context is saved. Previously, stored context could be incomplete, because `dataFlowAnalyzer.enterFunction(function)` wasn't called in all cases. ^KTIJ-26419 Fixed
This commit is contained in:
committed by
Space Team
parent
673ac2227a
commit
9548486b55
+6
@@ -82,6 +82,12 @@ public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGener
|
|||||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
|
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
|
@Test
|
||||||
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
||||||
public void testSmartCastInWhenEntryCondition() throws Exception {
|
public void testSmartCastInWhenEntryCondition() throws Exception {
|
||||||
|
|||||||
+6
@@ -82,6 +82,12 @@ public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerate
|
|||||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
|
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
|
@Test
|
||||||
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
||||||
public void testSmartCastInWhenEntryCondition() throws Exception {
|
public void testSmartCastInWhenEntryCondition() throws Exception {
|
||||||
|
|||||||
+6
@@ -82,6 +82,12 @@ public class FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestG
|
|||||||
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
|
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
|
@Test
|
||||||
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
@TestMetadata("smartCastInWhenEntryCondition.kt")
|
||||||
public void testSmartCastInWhenEntryCondition() throws Exception {
|
public void testSmartCastInWhenEntryCondition() throws Exception {
|
||||||
|
|||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun Any.test(): () -> Int = when {
|
||||||
|
this is A -> fun() = <expr>e</expr>
|
||||||
|
else -> { { 0 } }
|
||||||
|
}
|
||||||
+79
@@ -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
|
||||||
+282
@@ -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<kotlin/Int>
|
||||||
|
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
|
||||||
+5
-9
@@ -666,16 +666,12 @@ open class FirDeclarationsResolveTransformer(
|
|||||||
function: FirFunction,
|
function: FirFunction,
|
||||||
data: ResolutionMode
|
data: ResolutionMode
|
||||||
): FirStatement = whileAnalysing(session, function) {
|
): FirStatement = whileAnalysing(session, function) {
|
||||||
val functionIsNotAnalyzed = !function.bodyResolved
|
if (function.bodyResolved) return function
|
||||||
if (functionIsNotAnalyzed) {
|
dataFlowAnalyzer.enterFunction(function)
|
||||||
dataFlowAnalyzer.enterFunction(function)
|
|
||||||
}
|
|
||||||
return transformDeclarationContent(function, data).also {
|
return transformDeclarationContent(function, data).also {
|
||||||
if (functionIsNotAnalyzed) {
|
val result = it as FirFunction
|
||||||
val result = it as FirFunction
|
val controlFlowGraphReference = dataFlowAnalyzer.exitFunction(result)
|
||||||
val controlFlowGraphReference = dataFlowAnalyzer.exitFunction(result)
|
result.replaceControlFlowGraphReference(controlFlowGraphReference)
|
||||||
result.replaceControlFlowGraphReference(controlFlowGraphReference)
|
|
||||||
}
|
|
||||||
} as FirStatement
|
} as FirStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user