FIR: record 'suspend' function modifier in type references
This commit is contained in:
committed by
Mikhail Glukhikh
parent
bf97391c51
commit
88f81b9b71
+4
-3
@@ -1405,7 +1405,7 @@ class DeclarationsConverter(
|
||||
if (type.asText.isEmpty()) {
|
||||
return buildErrorTypeRef { diagnostic = ConeSimpleDiagnostic("Unwrapped type is null", DiagnosticKind.Syntax) }
|
||||
}
|
||||
var typeModifiers = TypeModifier() //TODO what with suspend?
|
||||
var typeModifiers = TypeModifier()
|
||||
var firType: FirTypeRef = buildErrorTypeRef { diagnostic = ConeSimpleDiagnostic("Incomplete code", DiagnosticKind.Syntax) }
|
||||
var afterLPar = false
|
||||
type.forEachChildren {
|
||||
@@ -1415,7 +1415,7 @@ class DeclarationsConverter(
|
||||
MODIFIER_LIST -> if (!afterLPar || typeModifiers.hasNoAnnotations()) typeModifiers = convertTypeModifierList(it)
|
||||
USER_TYPE -> firType = convertUserType(it)
|
||||
NULLABLE_TYPE -> firType = convertNullableType(it)
|
||||
FUNCTION_TYPE -> firType = convertFunctionType(it)
|
||||
FUNCTION_TYPE -> firType = convertFunctionType(it, isSuspend = typeModifiers.hasSuspend)
|
||||
DYNAMIC_TYPE -> firType = buildDynamicTypeRef {
|
||||
source = type.toFirSourceElement()
|
||||
isMarkedNullable = false
|
||||
@@ -1529,7 +1529,7 @@ class DeclarationsConverter(
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseFunctionType
|
||||
*/
|
||||
private fun convertFunctionType(functionType: LighterASTNode, isNullable: Boolean = false): FirTypeRef {
|
||||
private fun convertFunctionType(functionType: LighterASTNode, isNullable: Boolean = false, isSuspend: Boolean = false): FirTypeRef {
|
||||
var receiverTypeReference: FirTypeRef? = null
|
||||
lateinit var returnTypeReference: FirTypeRef
|
||||
val valueParametersList = mutableListOf<ValueParameter>()
|
||||
@@ -1550,6 +1550,7 @@ class DeclarationsConverter(
|
||||
if (receiverTypeReference != null) {
|
||||
annotations += extensionFunctionAnnotation
|
||||
}
|
||||
this.isSuspend = isSuspend
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,6 +1138,7 @@ class RawFirBuilder(
|
||||
FirFunctionTypeRefBuilder().apply {
|
||||
this.source = source
|
||||
isMarkedNullable = isNullable
|
||||
isSuspend = typeReference.hasModifier(SUSPEND_KEYWORD)
|
||||
receiverTypeRef = unwrappedElement.receiverTypeReference.convertSafe()
|
||||
// TODO: probably implicit type should not be here
|
||||
returnTypeRef = unwrappedElement.returnTypeReference.toFirOrErrorType()
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ class FirSpecificTypeResolverTransformer(
|
||||
source = functionTypeRef.source
|
||||
type = typeResolver.resolveType(functionTypeRef, towerScope)
|
||||
isMarkedNullable = functionTypeRef.isMarkedNullable
|
||||
isSuspend = functionTypeRef.isSuspend
|
||||
receiverTypeRef = functionTypeRef.receiverTypeRef
|
||||
returnTypeRef = functionTypeRef.returnTypeRef
|
||||
annotations += functionTypeRef.annotations
|
||||
|
||||
+4
-1
@@ -137,7 +137,10 @@ class FirIntegerOperator @FirImplementationDetail constructor(
|
||||
}
|
||||
}
|
||||
|
||||
class FirILTTypeRefPlaceHolder(isUnsigned: Boolean) : FirResolvedTypeRef() {
|
||||
class FirILTTypeRefPlaceHolder(
|
||||
isUnsigned: Boolean,
|
||||
override val isSuspend: Boolean = false
|
||||
) : FirResolvedTypeRef() {
|
||||
override val source: FirSourceElement? get() = null
|
||||
override val annotations: List<FirAnnotationCall> get() = emptyList()
|
||||
override var type: ConeIntegerLiteralType = ConeIntegerLiteralTypeImpl(0, isUnsigned)
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirComposedSuperTypeRef : FirPureAbstractElement(), FirTypeRef {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract val superTypeRefs: List<FirResolvedTypeRef>
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitComposedSuperTypeRef(this, data)
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirDelegatedTypeRef : FirPureAbstractElement(), FirTypeRef {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract val delegate: FirExpression?
|
||||
abstract val typeRef: FirTypeRef
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirDynamicTypeRef : FirPureAbstractElement(), FirTypeRefWithNullability {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract override val isMarkedNullable: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitDynamicTypeRef(this, data)
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirErrorTypeRef : FirResolvedTypeRef(), FirDiagnosticHolder {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract override val type: ConeKotlinType
|
||||
abstract override val delegatedTypeRef: FirTypeRef?
|
||||
abstract override val diagnostic: ConeDiagnostic
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
interface FirFunctionTypeRef : FirTypeRefWithNullability {
|
||||
override val source: FirSourceElement?
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
override val isSuspend: Boolean
|
||||
override val isMarkedNullable: Boolean
|
||||
val receiverTypeRef: FirTypeRef?
|
||||
val valueParameters: List<FirValueParameter>
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirImplicitTypeRef : FirPureAbstractElement(), FirTypeRef {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitImplicitTypeRef(this, data)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirResolvedFunctionTypeRef : FirResolvedTypeRef(), FirFunctionTypeRef {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract override val type: ConeKotlinType
|
||||
abstract override val delegatedTypeRef: FirTypeRef?
|
||||
abstract override val isMarkedNullable: Boolean
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirResolvedTypeRef : FirPureAbstractElement(), FirTypeRef {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract val type: ConeKotlinType
|
||||
abstract val delegatedTypeRef: FirTypeRef?
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
interface FirTypeRef : FirAnnotationContainer {
|
||||
override val source: FirSourceElement?
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
val isSuspend: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitTypeRef(this, data)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
interface FirTypeRefWithNullability : FirTypeRef {
|
||||
override val source: FirSourceElement?
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
override val isSuspend: Boolean
|
||||
val isMarkedNullable: Boolean
|
||||
|
||||
override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R = visitor.visitTypeRefWithNullability(this, data)
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
abstract class FirUserTypeRef : FirPureAbstractElement(), FirTypeRefWithNullability {
|
||||
abstract override val source: FirSourceElement?
|
||||
abstract override val annotations: List<FirAnnotationCall>
|
||||
abstract override val isSuspend: Boolean
|
||||
abstract override val isMarkedNullable: Boolean
|
||||
abstract val qualifier: List<FirQualifierPart>
|
||||
|
||||
|
||||
+2
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
class FirFunctionTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
override var source: FirSourceElement? = null
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
var isSuspend: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
var isMarkedNullable: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
var receiverTypeRef: FirTypeRef? = null
|
||||
val valueParameters: MutableList<FirValueParameter> = mutableListOf()
|
||||
@@ -35,6 +36,7 @@ class FirFunctionTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
return FirFunctionTypeRefImpl(
|
||||
source,
|
||||
annotations,
|
||||
isSuspend,
|
||||
isMarkedNullable,
|
||||
receiverTypeRef,
|
||||
valueParameters,
|
||||
|
||||
+2
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
class FirResolvedFunctionTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
override var source: FirSourceElement? = null
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
var isSuspend: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
lateinit var type: ConeKotlinType
|
||||
var isMarkedNullable: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
var receiverTypeRef: FirTypeRef? = null
|
||||
@@ -36,6 +37,7 @@ class FirResolvedFunctionTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
return FirResolvedFunctionTypeRefImpl(
|
||||
source,
|
||||
annotations,
|
||||
isSuspend,
|
||||
type,
|
||||
isMarkedNullable,
|
||||
receiverTypeRef,
|
||||
|
||||
+2
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
class FirResolvedTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
override var source: FirSourceElement? = null
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
var isSuspend: Boolean = false
|
||||
lateinit var type: ConeKotlinType
|
||||
var delegatedTypeRef: FirTypeRef? = null
|
||||
|
||||
@@ -32,6 +33,7 @@ class FirResolvedTypeRefBuilder : FirAnnotationContainerBuilder {
|
||||
return FirResolvedTypeRefImpl(
|
||||
source,
|
||||
annotations,
|
||||
isSuspend,
|
||||
type,
|
||||
delegatedTypeRef,
|
||||
)
|
||||
|
||||
+2
@@ -21,6 +21,8 @@ internal class FirComposedSuperTypeRefImpl(
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val superTypeRefs: MutableList<FirResolvedTypeRef>,
|
||||
) : FirComposedSuperTypeRef() {
|
||||
override val isSuspend: Boolean = false
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotations.forEach { it.accept(visitor, data) }
|
||||
superTypeRefs.forEach { it.accept(visitor, data) }
|
||||
|
||||
@@ -23,6 +23,7 @@ internal class FirDelegatedTypeRefImpl(
|
||||
) : FirDelegatedTypeRef() {
|
||||
override val source: FirSourceElement? get() = typeRef.source
|
||||
override val annotations: List<FirAnnotationCall> get() = typeRef.annotations
|
||||
override val isSuspend: Boolean = false
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
delegate?.accept(visitor, data)
|
||||
|
||||
@@ -20,6 +20,8 @@ internal class FirDynamicTypeRefImpl(
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val isMarkedNullable: Boolean,
|
||||
) : FirDynamicTypeRef() {
|
||||
override val isSuspend: Boolean = false
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotations.forEach { it.accept(visitor, data) }
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ internal class FirErrorTypeRefImpl(
|
||||
override val diagnostic: ConeDiagnostic,
|
||||
) : FirErrorTypeRef() {
|
||||
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
|
||||
override val isSuspend: Boolean = false
|
||||
override val type: ConeKotlinType = ConeClassErrorType(diagnostic.reason)
|
||||
override val delegatedTypeRef: FirTypeRef? get() = null
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
internal class FirFunctionTypeRefImpl(
|
||||
override val source: FirSourceElement?,
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val isSuspend: Boolean,
|
||||
override val isMarkedNullable: Boolean,
|
||||
override var receiverTypeRef: FirTypeRef?,
|
||||
override val valueParameters: MutableList<FirValueParameter>,
|
||||
|
||||
@@ -19,6 +19,7 @@ internal class FirImplicitTypeRefImpl(
|
||||
override val source: FirSourceElement?,
|
||||
) : FirImplicitTypeRef() {
|
||||
override val annotations: List<FirAnnotationCall> get() = emptyList()
|
||||
override val isSuspend: Boolean = false
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
}
|
||||
|
||||
+1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
internal class FirResolvedFunctionTypeRefImpl(
|
||||
override val source: FirSourceElement?,
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val isSuspend: Boolean,
|
||||
override val type: ConeKotlinType,
|
||||
override val isMarkedNullable: Boolean,
|
||||
override var receiverTypeRef: FirTypeRef?,
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.visitors.*
|
||||
internal class FirResolvedTypeRefImpl(
|
||||
override val source: FirSourceElement?,
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val isSuspend: Boolean,
|
||||
override val type: ConeKotlinType,
|
||||
override var delegatedTypeRef: FirTypeRef?,
|
||||
) : FirResolvedTypeRef() {
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ sealed class FirImplicitBuiltinTypeRef(
|
||||
override val source: FirSourceElement?,
|
||||
val id: ClassId,
|
||||
typeArguments: Array<out ConeTypeProjection> = emptyArray(),
|
||||
isNullable: Boolean = false
|
||||
isNullable: Boolean = false,
|
||||
override val isSuspend: Boolean = false
|
||||
) : FirResolvedTypeRef() {
|
||||
override val annotations: List<FirAnnotationCall>
|
||||
get() = emptyList()
|
||||
|
||||
@@ -19,7 +19,8 @@ open class FirUserTypeRefImpl(
|
||||
override val source: FirSourceElement?,
|
||||
override val isMarkedNullable: Boolean,
|
||||
override val qualifier: MutableList<FirQualifierPart>,
|
||||
override val annotations: MutableList<FirAnnotationCall>
|
||||
override val annotations: MutableList<FirAnnotationCall>,
|
||||
override val isSuspend: Boolean = false
|
||||
) : FirUserTypeRef(), FirAnnotationContainer {
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
|
||||
+1
@@ -232,6 +232,7 @@ object BuilderConfigurator : AbstractBuilderConfigurator<FirTreeBuilder>(FirTree
|
||||
}
|
||||
|
||||
builder(resolvedTypeRef) {
|
||||
defaultFalse("isSuspend")
|
||||
defaultNull("delegatedTypeRef")
|
||||
}
|
||||
|
||||
|
||||
+17
-4
@@ -376,6 +376,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
withGetter = true
|
||||
}
|
||||
default("annotations", "mutableListOf()")
|
||||
defaultFalse("isSuspend")
|
||||
useTypes(coneClassErrorTypeType)
|
||||
}
|
||||
|
||||
@@ -398,12 +399,23 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
useTypes(errorTypeRefImpl)
|
||||
}
|
||||
|
||||
impl(functionTypeRef)
|
||||
impl(implicitTypeRef) {
|
||||
defaultEmptyList("annotations")
|
||||
impl(dynamicTypeRef) {
|
||||
defaultFalse("isSuspend")
|
||||
}
|
||||
|
||||
impl(composedSuperTypeRef)
|
||||
impl(functionTypeRef) {
|
||||
// Note that we intentionally do _not_ set default value (false) for `isSuspend`, since function type reference is the only
|
||||
// place where type modifier `suspend` matters.
|
||||
}
|
||||
|
||||
impl(implicitTypeRef) {
|
||||
defaultEmptyList("annotations")
|
||||
defaultFalse("isSuspend")
|
||||
}
|
||||
|
||||
impl(composedSuperTypeRef) {
|
||||
defaultFalse("isSuspend")
|
||||
}
|
||||
|
||||
impl(reference, "FirStubReference") {
|
||||
default("source") {
|
||||
@@ -454,6 +466,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
delegate = "typeRef"
|
||||
}
|
||||
}
|
||||
defaultFalse("isSuspend")
|
||||
}
|
||||
|
||||
noImpl(userTypeRef)
|
||||
|
||||
+1
@@ -530,6 +530,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
|
||||
typeRef.configure {
|
||||
+annotations
|
||||
+booleanField("isSuspend")
|
||||
}
|
||||
|
||||
resolvedTypeRef.configure {
|
||||
|
||||
Reference in New Issue
Block a user