mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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.
This commit is contained in:
@@ -153,6 +153,17 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
if (auto *packElement = getAsExpr<PackElementExpr>(expr)) {
|
||||||
|
if (auto *outerEnvironment = CS.getPackEnvironment(packElement)) {
|
||||||
|
auto *expansionTy = CS.simplifyType(CS.getType(outerEnvironment))
|
||||||
|
->castTo<PackExpansionType>();
|
||||||
|
expansionTy->getCountType()->getTypeVariables(ReferencedVars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Action::Continue(expr);
|
return Action::Continue(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -748,13 +748,11 @@ do {
|
|||||||
(repeat takesClosure { each t }) // Ok
|
(repeat takesClosure { each t }) // Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: multi-statement closures should type-check.
|
|
||||||
func testMultiStmtClosure<each T>(_ t: repeat each T) -> (repeat each T) {
|
func testMultiStmtClosure<each T>(_ t: repeat each T) -> (repeat each T) {
|
||||||
(repeat takesClosure {
|
(repeat takesClosure {
|
||||||
// expected-error@-1 {{pack expansion requires that '_' and 'each T' have the same shape}}
|
|
||||||
let v = each t
|
let v = each t
|
||||||
return v
|
return v
|
||||||
})
|
}) // Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func takesAutoclosure<T>(_ fn: @autoclosure () -> T) -> T { return fn() }
|
func takesAutoclosure<T>(_ fn: @autoclosure () -> T) -> T { return fn() }
|
||||||
|
|||||||
Reference in New Issue
Block a user