mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] TypeSimplifier: If pattern and shape are packs - produce pattern type
The `transformWithPosition` would handle its flattening.
This commit is contained in:
committed by
Pavel Yaskevich
parent
8a39f3f38d
commit
f4a082d8f1
@@ -3793,13 +3793,14 @@ struct TypeSimplifier {
|
||||
}
|
||||
|
||||
if (auto expansion = dyn_cast<PackExpansionType>(type.getPointer())) {
|
||||
auto patternType = expansion->getPatternType();
|
||||
// First, let's check whether pattern type has all of the type variables
|
||||
// that represent packs resolved, otherwise we don't have enough information
|
||||
// to flatten this pack expansion type.
|
||||
//
|
||||
// Note that we don't actually need to do deep transformation here
|
||||
// because pack variables can only appear in structural positions.
|
||||
if (expansion->getPatternType().findIf([&](Type type) {
|
||||
if (patternType.findIf([&](Type type) {
|
||||
if (auto *typeVar = type->getAs<TypeVariableType>()) {
|
||||
if (typeVar->getImpl().canBindToPack())
|
||||
return GetFixedTypeFn(typeVar)->is<TypeVariableType>();
|
||||
@@ -3813,6 +3814,12 @@ struct TypeSimplifier {
|
||||
auto countType = expansion->getCountType().transform(
|
||||
TypeSimplifier(CS, GetFixedTypeFn));
|
||||
|
||||
// If both pattern and count are resolves, let's just return
|
||||
// the pattern type for `transformWithPosition` to take care
|
||||
// of the rest.
|
||||
if (patternType->is<PackType>() && countType->is<PackType>())
|
||||
return patternType;
|
||||
|
||||
if (auto countPack = countType->getAs<PackType>()) {
|
||||
SmallVector<Type, 4> elts;
|
||||
ActivePackExpansions.push_back({false, 0});
|
||||
|
||||
Reference in New Issue
Block a user