[FIR] create snapshot of collected tower data context for declaration

KTIJ-26113
This commit is contained in:
aleksandrina-streltsova
2023-07-26 17:55:43 +03:00
committed by teamcity
parent af6672c87d
commit 9e50a3b71d
10 changed files with 398 additions and 392 deletions
@@ -76,6 +76,12 @@ public class FirIdeDependentAnalysisSourceModuleScopeContextForPositionTestGener
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
} }
@Test
@TestMetadata("smartCastInAnonymousFunction.kt")
public void testSmartCastInAnonymousFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
@Test @Test
@TestMetadata("smartCastInWhenEntryCondition.kt") @TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception { public void testSmartCastInWhenEntryCondition() throws Exception {
@@ -76,6 +76,12 @@ public class FirIdeNormalAnalysisSourceModuleScopeContextForPositionTestGenerate
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
} }
@Test
@TestMetadata("smartCastInAnonymousFunction.kt")
public void testSmartCastInAnonymousFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
@Test @Test
@TestMetadata("smartCastInWhenEntryCondition.kt") @TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception { public void testSmartCastInWhenEntryCondition() throws Exception {
@@ -76,6 +76,12 @@ public class FirStandaloneNormalAnalysisSourceModuleScopeContextForPositionTestG
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt"); runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/simpleScopeContextForPosition.kt");
} }
@Test
@TestMetadata("smartCastInAnonymousFunction.kt")
public void testSmartCastInAnonymousFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/scopeProvider/scopeContextForPosition/smartCastInAnonymousFunction.kt");
}
@Test @Test
@TestMetadata("smartCastInWhenEntryCondition.kt") @TestMetadata("smartCastInWhenEntryCondition.kt")
public void testSmartCastInWhenEntryCondition() throws Exception { public void testSmartCastInWhenEntryCondition() throws Exception {
@@ -1,14 +1,5 @@
interface List<T> {
fun add(e: T)
fun get(index: Int): T
}
inline fun <E> buildList(f: List<E>.() -> Unit): List<E> = l
fun test() { fun test() {
buildList { with(t) {
with(this.get(0)) { <expr>e</expr>
<expr>e</expr>
}
} }
} }
@@ -1,9 +1,6 @@
element: e element: e
implicit receivers: implicit receivers:
type: ERROR(Cannot infer argument for type parameter E) type: ERROR(Cannot infer argument for type parameter T)
owner symbol: KtFirAnonymousFunctionSymbol
type: List<ERROR(Cannot infer argument for type parameter E)>
owner symbol: KtFirAnonymousFunctionSymbol owner symbol: KtFirAnonymousFunctionSymbol
scopes: scopes:
@@ -25,42 +22,19 @@ scopes:
callables: 0 callables: 0
constructors: 0 constructors: 0
TypeScope, index = 3 LocalScope, index = 3
packages: 0
classifiers: 0
callables: 5
fun add(e: T)
fun get(index: kotlin.Int): T
fun equals(other: kotlin.Any?): kotlin.Boolean
fun hashCode(): kotlin.Int
fun toString(): kotlin.String
constructors: 0
LocalScope, index = 4
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
LocalScope, index = 5 ExplicitSimpleImportingScope, index = 4
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
LocalScope, index = 6 PackageMemberScope, index = 5
packages: 0
classifiers: 0
callables: 0
constructors: 0
ExplicitSimpleImportingScope, index = 7
packages: 0
classifiers: 0
callables: 0
constructors: 0
PackageMemberScope, index = 8
packages: 6 packages: 6
META-INF META-INF
java java
@@ -68,24 +42,22 @@ scopes:
kotlin kotlin
org org
sun sun
classifiers: 1 classifiers: 0
interface List<T> callables: 1
callables: 2
fun <E> buildList(f: List<E>.() -> kotlin.Unit): List<E>
fun test() fun test()
constructors: 0 constructors: 0
DefaultSimpleImportingScope, index = 9 DefaultSimpleImportingScope, index = 6
DefaultSimpleImportingScope, index = 10 DefaultSimpleImportingScope, index = 7
ExplicitStarImportingScope, index = 11 ExplicitStarImportingScope, index = 8
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
DefaultSimpleImportingScope, index = 12 DefaultSimpleImportingScope, index = 9
DefaultStarImportingScope, index = 13 DefaultStarImportingScope, index = 10
@@ -2,17 +2,7 @@ element: e
implicit receivers: implicit receivers:
type: KtTypeErrorType: type: KtTypeErrorType:
annotationsList: [] annotationsList: []
type: ERROR CLASS: Cannot infer argument for type parameter E type: ERROR CLASS: Cannot infer argument for type parameter T
owner symbol: KtFirAnonymousFunctionSymbol
type: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtTypeErrorType:
annotationsList: []
type: ERROR CLASS: Cannot infer argument for type parameter E
]
type: List<ERROR CLASS: Cannot infer argument for type parameter E>
owner symbol: KtFirAnonymousFunctionSymbol owner symbol: KtFirAnonymousFunctionSymbol
scopes: scopes:
@@ -34,243 +24,19 @@ scopes:
callables: 0 callables: 0
constructors: 0 constructors: 0
TypeScope, index = 3 LocalScope, index = 3
packages: 0
classifiers: 0
callables: 5
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /List.add
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: ABSTRACT
name: add
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
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: e
origin: SOURCE
receiverParameter: null
returnType: KtTypeParameterType:
annotationsList: []
type: T
symbolKind: LOCAL
typeParameters: []
]
visibility: Public
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /List.get
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: ABSTRACT
name: get
origin: SOURCE
receiverParameter: null
returnType: KtTypeParameterType:
annotationsList: []
type: T
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: index
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Int
symbolKind: LOCAL
typeParameters: []
]
visibility: Public
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: 0
LocalScope, index = 4
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
LocalScope, index = 5 ExplicitSimpleImportingScope, index = 4
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
LocalScope, index = 6 PackageMemberScope, index = 5
packages: 0
classifiers: 0
callables: 0
constructors: 0
ExplicitSimpleImportingScope, index = 7
packages: 0
classifiers: 0
callables: 0
constructors: 0
PackageMemberScope, index = 8
packages: 6 packages: 6
KtPackageSymbol: KtPackageSymbol:
fqName: META-INF fqName: META-INF
@@ -290,104 +56,8 @@ scopes:
KtPackageSymbol: KtPackageSymbol:
fqName: sun fqName: sun
origin: SOURCE origin: SOURCE
classifiers: 1 classifiers: 0
KtNamedClassOrObjectSymbol: callables: 1
annotationsList: []
classIdIfNonLocal: List
classKind: INTERFACE
companionObject: null
contextReceivers: []
isActual: false
isData: false
isExpect: false
isExternal: false
isFun: false
isInline: false
isInner: false
modality: ABSTRACT
name: List
origin: SOURCE
superTypes: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Any
]
symbolKind: TOP_LEVEL
typeParameters: [
KtTypeParameterSymbol(T)
]
visibility: Public
callables: 2
KtFunctionSymbol:
annotationsList: []
callableIdIfNonLocal: /buildList
contextReceivers: []
contractEffects: []
hasStableParameterNames: true
isActual: false
isBuiltinFunctionInvoke: false
isExpect: false
isExtension: false
isExternal: false
isInfix: false
isInline: true
isOperator: false
isOverride: false
isStatic: false
isSuspend: false
modality: FINAL
name: buildList
origin: SOURCE
receiverParameter: null
returnType: KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtTypeParameterType:
annotationsList: []
type: E
]
type: List<E>
symbolKind: TOP_LEVEL
typeParameters: [
KtTypeParameterSymbol(E)
]
valueParameters: [
KtValueParameterSymbol:
annotationsList: []
callableIdIfNonLocal: null
contextReceivers: []
generatedPrimaryConstructorProperty: null
hasDefaultValue: false
isCrossinline: false
isExtension: false
isImplicitLambdaParameter: false
isNoinline: false
isVararg: false
name: f
origin: SOURCE
receiverParameter: null
returnType: KtFunctionalType:
annotationsList: []
ownTypeArguments: [
KtUsualClassType:
annotationsList: []
ownTypeArguments: [
KtTypeParameterType:
annotationsList: []
type: E
]
type: List<E>
KtUsualClassType:
annotationsList: []
ownTypeArguments: []
type: kotlin/Unit
]
type: @ExtensionFunctionType kotlin/Function1<List<E>, kotlin/Unit>
symbolKind: LOCAL
typeParameters: []
]
visibility: Public
KtFunctionSymbol: KtFunctionSymbol:
annotationsList: [] annotationsList: []
callableIdIfNonLocal: /test callableIdIfNonLocal: /test
@@ -419,16 +89,17 @@ scopes:
visibility: Public visibility: Public
constructors: 0 constructors: 0
DefaultSimpleImportingScope, index = 9 DefaultSimpleImportingScope, index = 6
DefaultSimpleImportingScope, index = 10 DefaultSimpleImportingScope, index = 7
ExplicitStarImportingScope, index = 11 ExplicitStarImportingScope, index = 8
packages: 0 packages: 0
classifiers: 0 classifiers: 0
callables: 0 callables: 0
constructors: 0 constructors: 0
DefaultSimpleImportingScope, index = 12 DefaultSimpleImportingScope, index = 9
DefaultStarImportingScope, index = 10
DefaultStarImportingScope, index = 13
@@ -0,0 +1,4 @@
class A
fun Any.test() = if (this is A) ({ <expr>e</expr> }) else ({ 2 })
@@ -0,0 +1,73 @@
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
TypeScope, index = 3
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 = 4
packages: 0
classifiers: 0
callables: 0
constructors: 0
ExplicitSimpleImportingScope, index = 5
packages: 0
classifiers: 0
callables: 0
constructors: 0
PackageMemberScope, index = 6
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 = 7
DefaultSimpleImportingScope, index = 8
ExplicitStarImportingScope, index = 9
packages: 0
classifiers: 0
callables: 0
constructors: 0
DefaultSimpleImportingScope, index = 10
DefaultStarImportingScope, index = 11
@@ -0,0 +1,277 @@
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
TypeScope, index = 3
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 = 4
packages: 0
classifiers: 0
callables: 0
constructors: 0
ExplicitSimpleImportingScope, index = 5
packages: 0
classifiers: 0
callables: 0
constructors: 0
PackageMemberScope, index = 6
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 = 7
DefaultSimpleImportingScope, index = 8
ExplicitStarImportingScope, index = 9
packages: 0
classifiers: 0
callables: 0
constructors: 0
DefaultSimpleImportingScope, index = 10
DefaultStarImportingScope, index = 11
@@ -62,7 +62,7 @@ internal class FirTowerDataContextAllElementsCollector : FirResolveContextCollec
// we do not collect contexts for such declarations // we do not collect contexts for such declarations
if (psi is KtDelegatedSuperTypeEntry) return if (psi is KtDelegatedSuperTypeEntry) return
elementsToContext[psi] = context.towerDataContext elementsToContext[psi] = context.towerDataContext.createSnapshot()
} }
override fun addClassHeaderContext(declaration: FirRegularClass, context: FirTowerDataContext) { override fun addClassHeaderContext(declaration: FirRegularClass, context: FirTowerDataContext) {