mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CS] NFC: Factor out matchPackElementType
This commit is contained in:
@@ -9626,6 +9626,49 @@ ConstraintSystem::simplifyBindTupleOfFunctionParamsConstraint(
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
ConstraintSystem::SolutionKind
|
||||
ConstraintSystem::matchPackElementType(Type elementType, Type patternType,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
auto *loc = getConstraintLocator(locator);
|
||||
auto shapeClass = patternType->getReducedShape();
|
||||
auto *elementEnv = getPackElementEnvironment(loc, shapeClass);
|
||||
|
||||
// Without an opened element environment, we cannot derive the
|
||||
// element binding.
|
||||
if (!elementEnv) {
|
||||
if (!shouldAttemptFixes())
|
||||
return SolutionKind::Error;
|
||||
|
||||
// `each` was applied to a concrete type.
|
||||
if (!shapeClass->is<PackArchetypeType>()) {
|
||||
if (recordFix(AllowInvalidPackElement::create(*this, patternType, loc)))
|
||||
return SolutionKind::Error;
|
||||
} else {
|
||||
auto envShape = PackExpansionEnvironments.find(loc);
|
||||
if (envShape == PackExpansionEnvironments.end()) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
auto *fix = SkipSameShapeRequirement::create(
|
||||
*this, envShape->second.second, shapeClass,
|
||||
getConstraintLocator(loc, ConstraintLocator::PackShape));
|
||||
if (recordFix(fix)) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
}
|
||||
|
||||
recordAnyTypeVarAsPotentialHole(elementType);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
auto expectedElementTy =
|
||||
elementEnv->mapContextualPackTypeIntoElementContext(patternType);
|
||||
assert(!expectedElementTy->is<PackType>());
|
||||
|
||||
addConstraint(ConstraintKind::Equal, elementType, expectedElementTy,
|
||||
locator);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
ConstraintSystem::SolutionKind
|
||||
ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
|
||||
TypeMatchOptions flags,
|
||||
@@ -9660,46 +9703,8 @@ ConstraintSystem::simplifyPackElementOfConstraint(Type first, Type second,
|
||||
}
|
||||
|
||||
// Let's try to resolve element type based on the pattern type.
|
||||
if (!patternType->hasTypeVariable()) {
|
||||
auto *loc = getConstraintLocator(locator);
|
||||
auto shapeClass = patternType->getReducedShape();
|
||||
auto *elementEnv = getPackElementEnvironment(loc, shapeClass);
|
||||
|
||||
// Without an opened element environment, we cannot derive the
|
||||
// element binding.
|
||||
if (!elementEnv) {
|
||||
if (!shouldAttemptFixes())
|
||||
return SolutionKind::Error;
|
||||
|
||||
// `each` was applied to a concrete type.
|
||||
if (!shapeClass->is<PackArchetypeType>()) {
|
||||
if (recordFix(AllowInvalidPackElement::create(*this, patternType, loc)))
|
||||
return SolutionKind::Error;
|
||||
} else {
|
||||
auto envShape = PackExpansionEnvironments.find(loc);
|
||||
if (envShape == PackExpansionEnvironments.end()) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
auto *fix = SkipSameShapeRequirement::create(
|
||||
*this, envShape->second.second, shapeClass,
|
||||
getConstraintLocator(loc, ConstraintLocator::PackShape));
|
||||
if (recordFix(fix)) {
|
||||
return SolutionKind::Error;
|
||||
}
|
||||
}
|
||||
|
||||
recordAnyTypeVarAsPotentialHole(elementType);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
|
||||
auto expectedElementTy =
|
||||
elementEnv->mapContextualPackTypeIntoElementContext(patternType);
|
||||
assert(!expectedElementTy->is<PackType>());
|
||||
|
||||
addConstraint(ConstraintKind::Equal, elementType, expectedElementTy,
|
||||
locator);
|
||||
return SolutionKind::Solved;
|
||||
}
|
||||
if (!patternType->hasTypeVariable())
|
||||
return matchPackElementType(elementType, patternType, locator);
|
||||
|
||||
// Otherwise we are inferred or checking pattern type.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user