Skip to content

Commit c41341d

Browse files
committed
Sema: Fix matchCallArguments() to allow empty pack type bindings
Thanks to @hborla for suggesting this fix.
1 parent 74a6350 commit c41341d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,10 +1423,14 @@ class OpenParameterPackElements {
14231423

14241424
void intoPackTypes(llvm::function_ref<void(TypeVariableType *, Type)> fn) && {
14251425
if (argIdx == -1) {
1426-
(void)patternTy.transform(*this);
1427-
for (auto &entry : PackElementCache) {
1428-
entry.second.clear();
1429-
}
1426+
// No arguments. Each pack in the pattern will have no elements.
1427+
patternTy.visit([&](Type type) {
1428+
auto *typeVar = type->getAs<TypeVariableType>();
1429+
if (!typeVar || !typeVar->getImpl().getGenericParameter()->isParameterPack())
1430+
return;
1431+
1432+
this->PackElementCache[typeVar].clear();
1433+
});
14301434
}
14311435

14321436
for (const auto &entry : PackElementCache) {

test/Constraints/variadic_generic_functions.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@ func invalidPacks() {
2626

2727
func call() {
2828
func multipleParameters<T...>(xs: T..., ys: T...) -> (T...) { return (_: xs) }
29-
// expected-note@-1 {{in call to function 'multipleParameters(xs:ys:)'}}
30-
_ = multipleParameters()
31-
// expected-error@-1 2 {{generic parameter 'T' could not be inferred}}
29+
multipleParameters()
30+
3231
let x: (_: String) = multipleParameters(xs: "", ys: "")
3332
let (one, two) = multipleParameters(xs: "", 5.0, ys: "", 5.0)
3433
multipleParameters(xs: "", 5.0, ys: 5.0, "") // expected-error {{type of expression is ambiguous without more context}}
3534

3635
func multipleSequences<T..., U...>(xs: T..., ys: U...) -> (T...) { return (_: ys) }
37-
// expected-note@-1 {{in call to function 'multipleSequences(xs:ys:)'}}
38-
// expected-error@-2 {{cannot convert return expression of type '(U...)' to return type '(T...)'}}
36+
// expected-error@-1 {{cannot convert return expression of type '(U...)' to return type '(T...)'}}
3937

40-
_ = multipleSequences()
41-
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
42-
// expected-error@-2 {{generic parameter 'U' could not be inferred}}
38+
multipleSequences()
4339
_ = multipleSequences(xs: "", ys: "")
4440
_ = multipleSequences(xs: "", 5.0, ys: 5.0, "")
4541
}

0 commit comments

Comments
 (0)