[FIR] Extract adding of constraints from expected type to separate method
This commit is contained in:
committed by
TeamCityServer
parent
def799cc4e
commit
8624d97f29
+44
-28
@@ -99,34 +99,15 @@ class FirCallCompleter(
|
|||||||
session.lookupTracker?.recordTypeResolveAsLookup(resolvedTypeRef, call.source, null)
|
session.lookupTracker?.recordTypeResolveAsLookup(resolvedTypeRef, call.source, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
val expectedTypeConstraintPosition = ConeExpectedTypeConstraintPosition(expectedTypeMismatchIsReportedInChecker)
|
addConstraintFromExpectedType(
|
||||||
|
expectedTypeMismatchIsReportedInChecker,
|
||||||
when {
|
expectedTypeRef,
|
||||||
expectedTypeRef !is FirResolvedTypeRef -> {
|
shouldEnforceExpectedType,
|
||||||
// nothing
|
candidate,
|
||||||
}
|
initialType,
|
||||||
!shouldEnforceExpectedType -> {
|
isFromCast,
|
||||||
candidate.system.addSubtypeConstraintIfCompatible(
|
mayBeCoercionToUnitApplied
|
||||||
initialType, expectedTypeRef.type, expectedTypeConstraintPosition
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
isFromCast -> when {
|
|
||||||
candidate.isFunctionForExpectTypeFromCastFeature() -> {
|
|
||||||
candidate.system.addSubtypeConstraint(
|
|
||||||
initialType, expectedTypeRef.type,
|
|
||||||
ConeExpectedTypeConstraintPosition(expectedTypeMismatchIsReportedInChecker = false),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
!expectedTypeRef.coneType.isUnitOrFlexibleUnit || !mayBeCoercionToUnitApplied -> {
|
|
||||||
candidate.system.addSubtypeConstraint(initialType, expectedTypeRef.type, expectedTypeConstraintPosition)
|
|
||||||
}
|
|
||||||
candidate.system.notFixedTypeVariables.isNotEmpty() -> {
|
|
||||||
candidate.system.addSubtypeConstraintIfCompatible(
|
|
||||||
initialType, expectedTypeRef.type, expectedTypeConstraintPosition
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val completionMode = candidate.computeCompletionMode(session.inferenceComponents, expectedTypeRef, initialType)
|
val completionMode = candidate.computeCompletionMode(session.inferenceComponents, expectedTypeRef, initialType)
|
||||||
|
|
||||||
@@ -165,6 +146,41 @@ class FirCallCompleter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addConstraintFromExpectedType(
|
||||||
|
expectedTypeMismatchIsReportedInChecker: Boolean,
|
||||||
|
expectedTypeRef: FirTypeRef?,
|
||||||
|
shouldEnforceExpectedType: Boolean,
|
||||||
|
candidate: Candidate,
|
||||||
|
initialType: ConeKotlinType,
|
||||||
|
isFromCast: Boolean,
|
||||||
|
mayBeCoercionToUnitApplied: Boolean
|
||||||
|
) {
|
||||||
|
val expectedType = expectedTypeRef?.coneTypeSafe<ConeKotlinType>() ?: return
|
||||||
|
val expectedTypeConstraintPosition = ConeExpectedTypeConstraintPosition(expectedTypeMismatchIsReportedInChecker)
|
||||||
|
|
||||||
|
val system = candidate.system
|
||||||
|
when {
|
||||||
|
!shouldEnforceExpectedType -> {
|
||||||
|
system.addSubtypeConstraintIfCompatible(initialType, expectedType, expectedTypeConstraintPosition)
|
||||||
|
}
|
||||||
|
isFromCast -> {
|
||||||
|
if (candidate.isFunctionForExpectTypeFromCastFeature()) {
|
||||||
|
system.addSubtypeConstraint(
|
||||||
|
initialType, expectedType,
|
||||||
|
ConeExpectedTypeConstraintPosition(expectedTypeMismatchIsReportedInChecker = false),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
!expectedType.isUnitOrFlexibleUnit || !mayBeCoercionToUnitApplied -> {
|
||||||
|
system.addSubtypeConstraint(initialType, expectedType, expectedTypeConstraintPosition)
|
||||||
|
}
|
||||||
|
system.notFixedTypeVariables.isEmpty() -> return
|
||||||
|
else -> {
|
||||||
|
system.addSubtypeConstraintIfCompatible(initialType, expectedType, expectedTypeConstraintPosition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun <T> runCompletionForCall(
|
fun <T> runCompletionForCall(
|
||||||
candidate: Candidate,
|
candidate: Candidate,
|
||||||
completionMode: ConstraintSystemCompletionMode,
|
completionMode: ConstraintSystemCompletionMode,
|
||||||
|
|||||||
Reference in New Issue
Block a user