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