[FIR] refactoring, use data class instead of a Pair in FirTypeResolver.resolveType
This commit is contained in:
committed by
Space Team
parent
672cc85949
commit
7c87eb098d
@@ -23,7 +23,12 @@ abstract class FirTypeResolver : FirSessionComponent {
|
||||
// Note: sometimes we don't have useSiteFile in IDE context
|
||||
useSiteFile: FirFile?,
|
||||
supertypeSupplier: SupertypeSupplier
|
||||
): Pair<ConeKotlinType, ConeDiagnostic?>
|
||||
): FirTypeResolutionResult
|
||||
}
|
||||
|
||||
data class FirTypeResolutionResult(
|
||||
val type: ConeKotlinType,
|
||||
val diagnostic: ConeDiagnostic?,
|
||||
)
|
||||
|
||||
val FirSession.typeResolver: FirTypeResolver by FirSession.sessionComponentAccessor()
|
||||
|
||||
+17
-13
@@ -449,7 +449,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
private fun createFunctionType(
|
||||
typeRef: FirFunctionTypeRef,
|
||||
containerDeclaration: FirDeclaration? = null
|
||||
): Pair<ConeClassLikeTypeImpl, ConeDiagnostic?> {
|
||||
): FirTypeResolutionResult {
|
||||
val parameters =
|
||||
typeRef.contextReceiverTypeRefs.map { it.coneType } +
|
||||
listOfNotNull(typeRef.receiverTypeRef?.coneType) +
|
||||
@@ -482,12 +482,15 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
containerDeclaration,
|
||||
shouldExpandTypeAliases = true
|
||||
)
|
||||
return ConeClassLikeTypeImpl(
|
||||
classId.toLookupTag(),
|
||||
parameters.toTypedArray(),
|
||||
typeRef.isMarkedNullable,
|
||||
attributes
|
||||
) to diagnostic
|
||||
return FirTypeResolutionResult(
|
||||
ConeClassLikeTypeImpl(
|
||||
classId.toLookupTag(),
|
||||
parameters.toTypedArray(),
|
||||
typeRef.isMarkedNullable,
|
||||
attributes
|
||||
),
|
||||
diagnostic
|
||||
)
|
||||
}
|
||||
|
||||
override fun resolveType(
|
||||
@@ -498,28 +501,29 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
resolveDeprecations: Boolean,
|
||||
useSiteFile: FirFile?,
|
||||
supertypeSupplier: SupertypeSupplier
|
||||
): Pair<ConeKotlinType, ConeDiagnostic?> {
|
||||
): FirTypeResolutionResult {
|
||||
return when (typeRef) {
|
||||
is FirResolvedTypeRef -> error("Do not resolve, resolved type-refs")
|
||||
is FirUserTypeRef -> {
|
||||
val result = resolveUserTypeToSymbol(typeRef, scopeClassDeclaration, useSiteFile, supertypeSupplier, resolveDeprecations)
|
||||
resolveUserType(
|
||||
val resolvedType = resolveUserType(
|
||||
typeRef,
|
||||
result,
|
||||
areBareTypesAllowed,
|
||||
scopeClassDeclaration.topContainer ?: scopeClassDeclaration.containingDeclarations.lastOrNull(),
|
||||
scopeClassDeclaration.containerDeclaration,
|
||||
isOperandOfIsOperator,
|
||||
) to (result as? TypeResolutionResult.Resolved)?.typeCandidate?.diagnostic
|
||||
)
|
||||
FirTypeResolutionResult(resolvedType, (result as? TypeResolutionResult.Resolved)?.typeCandidate?.diagnostic)
|
||||
}
|
||||
is FirFunctionTypeRef -> createFunctionType(typeRef, scopeClassDeclaration.containerDeclaration)
|
||||
is FirDynamicTypeRef -> ConeDynamicType.create(session) to null
|
||||
is FirDynamicTypeRef -> FirTypeResolutionResult(ConeDynamicType.create(session), diagnostic = null)
|
||||
is FirIntersectionTypeRef -> {
|
||||
val leftType = typeRef.leftType.coneType
|
||||
if (leftType is ConeTypeParameterType) {
|
||||
ConeDefinitelyNotNullType(leftType) to null
|
||||
FirTypeResolutionResult(ConeDefinitelyNotNullType(leftType), diagnostic = null)
|
||||
} else {
|
||||
ConeErrorType(ConeForbiddenIntersection) to null
|
||||
FirTypeResolutionResult(ConeErrorType(ConeForbiddenIntersection), diagnostic = null)
|
||||
}
|
||||
}
|
||||
else -> error(typeRef.render())
|
||||
|
||||
+4
-3
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.resolve.FirTypeResolutionResult
|
||||
import org.jetbrains.kotlin.fir.resolve.SupertypeSupplier
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnsupportedDefaultValueInFunctionType
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||
@@ -95,8 +96,8 @@ class FirSpecificTypeResolverTransformer(
|
||||
val scopeOwnerLookupNames = data.scopes.flatMap { it.scopeOwnerLookupNames }
|
||||
session.lookupTracker?.recordTypeLookup(functionTypeRef, scopeOwnerLookupNames, currentFile?.source)
|
||||
val resolvedTypeWithDiagnostic = resolveType(functionTypeRef, data)
|
||||
val resolvedType = resolvedTypeWithDiagnostic.first.takeIfAcceptable()
|
||||
val diagnostic = resolvedTypeWithDiagnostic.second
|
||||
val resolvedType = resolvedTypeWithDiagnostic.type.takeIfAcceptable()
|
||||
val diagnostic = resolvedTypeWithDiagnostic.diagnostic
|
||||
return if (resolvedType != null && resolvedType !is ConeErrorType && diagnostic == null) {
|
||||
buildResolvedTypeRef {
|
||||
source = functionTypeRef.source
|
||||
@@ -120,7 +121,7 @@ class FirSpecificTypeResolverTransformer(
|
||||
private fun FirSpecificTypeResolverTransformer.resolveType(
|
||||
typeRef: FirTypeRef,
|
||||
scopeClassDeclaration: ScopeClassDeclaration,
|
||||
): Pair<ConeKotlinType, ConeDiagnostic?> {
|
||||
): FirTypeResolutionResult {
|
||||
return typeResolver.resolveType(
|
||||
typeRef,
|
||||
scopeClassDeclaration,
|
||||
|
||||
Reference in New Issue
Block a user