Skip to content

Commit 10adbdd

Browse files
committed
[ConstraintSystem] Correct the first type of the ShapeOf constraint when
generating constraints for PackExpansionExpr. The result pattern type of a pack expansion doesn't always contain pack references. Instead, use the type of the first pack reference binding.
1 parent 5766b56 commit 10adbdd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2932,7 +2932,10 @@ namespace {
29322932
auto *shapeTypeVar = CS.createTypeVariable(shapeLoc,
29332933
TVO_CanBindToPack |
29342934
TVO_CanBindToHole);
2935-
CS.addConstraint(ConstraintKind::ShapeOf, patternTy, shapeTypeVar,
2935+
auto packReference = expr->getBindings().front();
2936+
auto packType = CS.simplifyType(CS.getType(packReference))
2937+
->castTo<PackExpansionType>()->getPatternType();
2938+
CS.addConstraint(ConstraintKind::ShapeOf, packType, shapeTypeVar,
29362939
CS.getConstraintLocator(expr));
29372940

29382941
return PackExpansionType::get(patternTy, shapeTypeVar);

test/Constraints/pack-expansion-expressions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ func outerArchetype<T..., U>(t: T..., u: U) where T: P {
5858
func sameElement<T..., U>(t: T..., u: U) where T: P, T == U {
5959
let _: T... = t.f(u)...
6060
}
61+
62+
func forEachEach<C..., U>(c: C..., function: (U) -> Void)
63+
where C: Collection, C.Element == U {
64+
_ = c.forEach(function)...
65+
}

0 commit comments

Comments
 (0)