AA: introduce KtDynamicType
This commit is contained in:
committed by
Ilya Kirillov
parent
e81231a78f
commit
2d52c59bc7
+1
@@ -232,6 +232,7 @@ private fun <T : CallableDescriptor> T.unwrapUseSiteSubstitutionOverride(): T {
|
||||
|
||||
internal fun KotlinType.toKtType(analysisContext: Fe10AnalysisContext): KtType {
|
||||
return when (val unwrappedType = unwrap()) {
|
||||
is DynamicType -> KtFe10DynamicType(unwrappedType, analysisContext)
|
||||
is FlexibleType -> KtFe10FlexibleType(unwrappedType, analysisContext)
|
||||
is DefinitelyNotNullType -> KtFe10DefinitelyNotNullType(unwrappedType, analysisContext)
|
||||
is ErrorType -> KtFe10ClassErrorType(unwrappedType, analysisContext)
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisContext
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.ktNullability
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.KtFe10Type
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.types.base.asStringForDebugging
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtDynamicType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.types.DynamicType
|
||||
|
||||
internal class KtFe10DynamicType(
|
||||
override val type: DynamicType,
|
||||
override val analysisContext: Fe10AnalysisContext
|
||||
) : KtDynamicType(), KtFe10Type {
|
||||
override fun asStringForDebugging(): String = withValidityAssertion { type.asStringForDebugging() }
|
||||
|
||||
override val nullability: KtTypeNullability
|
||||
get() = withValidityAssertion { type.ktNullability }
|
||||
}
|
||||
+6
@@ -112,6 +112,12 @@ public class Fe10IdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends A
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dynamic.kt")
|
||||
public void testDynamic() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/dynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
|
||||
+1
@@ -436,6 +436,7 @@ internal class KtSymbolByFirBuilder constructor(
|
||||
}
|
||||
is ConeTypeParameterType -> KtFirTypeParameterType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
is ConeErrorType -> KtFirClassErrorType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
is ConeDynamicType -> KtFirDynamicType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
is ConeFlexibleType -> KtFirFlexibleType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder)
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.fir.types
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtSymbolByFirBuilder
|
||||
import org.jetbrains.kotlin.analysis.api.fir.annotations.KtFirAnnotationListForType
|
||||
import org.jetbrains.kotlin.analysis.api.fir.utils.cached
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtDynamicType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeNullability
|
||||
import org.jetbrains.kotlin.fir.types.ConeDynamicType
|
||||
import org.jetbrains.kotlin.fir.types.render
|
||||
|
||||
internal class KtFirDynamicType(
|
||||
override val coneType: ConeDynamicType,
|
||||
override val token: KtLifetimeToken,
|
||||
private val builder: KtSymbolByFirBuilder,
|
||||
) : KtDynamicType(), KtFirType {
|
||||
override val annotationsList: KtAnnotationsList by cached {
|
||||
KtFirAnnotationListForType.create(coneType, builder.rootSession, token)
|
||||
}
|
||||
override val nullability: KtTypeNullability get() = withValidityAssertion { coneType.nullability.asKtNullability() }
|
||||
|
||||
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
||||
override fun equals(other: Any?) = typeEquals(other)
|
||||
override fun hashCode() = typeHashcode()
|
||||
}
|
||||
+6
@@ -112,6 +112,12 @@ public class FirIdeNormalAnalysisSourceModuleSymbolByPsiTestGenerated extends Ab
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dynamic.kt")
|
||||
public void testDynamic() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/dynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
|
||||
+6
@@ -112,6 +112,12 @@ public class FirStandaloneNormalAnalysisSourceModuleSymbolByPsiTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/deprecated.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dynamic.kt")
|
||||
public void testDynamic() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/symbols/symbolByPsi/dynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enum.kt")
|
||||
public void testEnum() throws Exception {
|
||||
|
||||
@@ -107,5 +107,15 @@ public abstract class KtIntegerLiteralType : KtType {
|
||||
*/
|
||||
public abstract val possibleTypes: Collection<KtClassType>
|
||||
|
||||
override fun toString(): String = asStringForDebugging()
|
||||
}
|
||||
|
||||
/**
|
||||
* A special dynamic type, which is used to support interoperability with dynamically typed libraries, platforms or languages.
|
||||
*
|
||||
* Although this can be viewed as a flexible type (kotlin.Nothing..kotlin.Any?), a platform may assign special meaning to the
|
||||
* values of dynamic type, and handle differently from the regular flexible type.
|
||||
*/
|
||||
public abstract class KtDynamicType : KtType {
|
||||
override fun toString(): String = asStringForDebugging()
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
KtKotlinPropertySymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /Foo.p
|
||||
getter: KtPropertyGetterSymbol(<getter>)
|
||||
hasBackingField: true
|
||||
hasGetter: true
|
||||
hasSetter: false
|
||||
initializer: KtConstantInitializerValue(null)
|
||||
isConst: false
|
||||
isDelegatedProperty: false
|
||||
isExtension: false
|
||||
isFromPrimaryConstructor: false
|
||||
isLateInit: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isVal: true
|
||||
modality: FINAL
|
||||
name: p
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: ft<kotlin/Nothing, kotlin/Any?>
|
||||
setter: null
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getDispatchReceiver(): Foo
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
getterDeprecationStatus: null
|
||||
javaGetterName: getP
|
||||
javaSetterName: null
|
||||
setterDeprecationStatus: null
|
||||
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isVararg: false
|
||||
name: p
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: ft<kotlin/Nothing, kotlin/Any?>
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtAnonymousFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
hasStableParameterNames: true
|
||||
isExtension: false
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: ft<kotlin/Nothing, kotlin/Any?>
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /Foo.f
|
||||
hasStableParameterNames: true
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: f
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: ft<kotlin/Nothing, kotlin/Any?>
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol(p)
|
||||
]
|
||||
visibility: Public
|
||||
getDispatchReceiver(): Foo
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtNamedClassOrObjectSymbol:
|
||||
annotationsList: []
|
||||
classIdIfNonLocal: Foo
|
||||
classKind: CLASS
|
||||
companionObject: null
|
||||
isData: false
|
||||
isExternal: false
|
||||
isFun: false
|
||||
isInline: false
|
||||
isInner: false
|
||||
modality: FINAL
|
||||
name: Foo
|
||||
origin: SOURCE
|
||||
superTypes: [
|
||||
kotlin/Any
|
||||
]
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
val p : dynamic = null
|
||||
|
||||
fun f(p: dynamic): dynamic {
|
||||
run<dynamic> { "" }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
val p: (kotlin.Nothing..kotlin.Any?)
|
||||
|
||||
fun f(p: (kotlin.Nothing..kotlin.Any?)): (kotlin.Nothing..kotlin.Any?)
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
KtKotlinPropertySymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /Foo.p
|
||||
getter: KtPropertyGetterSymbol(<getter>)
|
||||
hasBackingField: true
|
||||
hasGetter: true
|
||||
hasSetter: false
|
||||
initializer: KtConstantInitializerValue(null)
|
||||
isConst: false
|
||||
isDelegatedProperty: false
|
||||
isExtension: false
|
||||
isFromPrimaryConstructor: false
|
||||
isLateInit: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isVal: true
|
||||
modality: FINAL
|
||||
name: p
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: dynamic
|
||||
setter: null
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getDispatchReceiver(): Foo
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
getterDeprecationStatus: null
|
||||
javaGetterName: getP
|
||||
javaSetterName: null
|
||||
setterDeprecationStatus: null
|
||||
|
||||
KtValueParameterSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
generatedPrimaryConstructorProperty: null
|
||||
hasDefaultValue: false
|
||||
isExtension: false
|
||||
isImplicitLambdaParameter: false
|
||||
isVararg: false
|
||||
name: p
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: dynamic
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtAnonymousFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: null
|
||||
hasStableParameterNames: true
|
||||
isExtension: false
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: dynamic
|
||||
symbolKind: LOCAL
|
||||
typeParameters: []
|
||||
valueParameters: []
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtFunctionSymbol:
|
||||
annotationsList: []
|
||||
callableIdIfNonLocal: /Foo.f
|
||||
hasStableParameterNames: true
|
||||
isBuiltinFunctionInvoke: false
|
||||
isExtension: false
|
||||
isExternal: false
|
||||
isInfix: false
|
||||
isInline: false
|
||||
isOperator: false
|
||||
isOverride: false
|
||||
isStatic: false
|
||||
isSuspend: false
|
||||
modality: FINAL
|
||||
name: f
|
||||
origin: SOURCE
|
||||
receiverType: null
|
||||
returnType: dynamic
|
||||
symbolKind: CLASS_MEMBER
|
||||
typeParameters: []
|
||||
valueParameters: [
|
||||
KtValueParameterSymbol(p)
|
||||
]
|
||||
visibility: Public
|
||||
getDispatchReceiver(): Foo
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
|
||||
KtNamedClassOrObjectSymbol:
|
||||
annotationsList: []
|
||||
classIdIfNonLocal: Foo
|
||||
classKind: CLASS
|
||||
companionObject: null
|
||||
isData: false
|
||||
isExternal: false
|
||||
isFun: false
|
||||
isInline: false
|
||||
isInner: false
|
||||
modality: FINAL
|
||||
name: Foo
|
||||
origin: SOURCE
|
||||
superTypes: [
|
||||
kotlin/Any
|
||||
]
|
||||
symbolKind: TOP_LEVEL
|
||||
typeParameters: []
|
||||
visibility: Public
|
||||
getContainingModule: KtSourceModule "Sources of main"
|
||||
deprecationStatus: null
|
||||
Reference in New Issue
Block a user