Skip to content

Commit bc3b274

Browse files
committed
[CSSyntacticElement] Bring type variables from outer pack expansion into scope
If closure appears inside of a pack expansion, the elements that reference pack elements have to bring expansion's shape type in scope to make sure that the shapes match.
1 parent 888ab81 commit bc3b274

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ class TypeVariableRefFinder : public ASTWalker {
153153
}
154154
}
155155

156+
// If closure appears inside of a pack expansion, the elements
157+
// that reference pack elements have to bring expansion's shape
158+
// type in scope to make sure that the shapes match.
159+
if (auto *packElement = getAsExpr<PackElementExpr>(expr)) {
160+
if (auto *outerEnvironment = CS.getPackEnvironment(packElement)) {
161+
auto *expansionTy = CS.simplifyType(CS.getType(outerEnvironment))
162+
->castTo<PackExpansionType>();
163+
expansionTy->getCountType()->getTypeVariables(ReferencedVars);
164+
}
165+
}
166+
156167
return Action::Continue(expr);
157168
}
158169

test/Constraints/pack-expansion-expressions.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,13 +748,11 @@ do {
748748
(repeat takesClosure { each t }) // Ok
749749
}
750750

751-
// FIXME: multi-statement closures should type-check.
752751
func testMultiStmtClosure<each T>(_ t: repeat each T) -> (repeat each T) {
753752
(repeat takesClosure {
754-
// expected-error@-1 {{pack expansion requires that '_' and 'each T' have the same shape}}
755753
let v = each t
756754
return v
757-
})
755+
}) // Ok
758756
}
759757

760758
func takesAutoclosure<T>(_ fn: @autoclosure () -> T) -> T { return fn() }

0 commit comments

Comments
 (0)