Skip to content

Commit a528000

Browse files
authored
Merge pull request #64259 from xedin/variadic-matching-fix
[CSSimplify] Variadics: Allow unlabeled matching after pack expansion…
2 parents 67644dc + 3620010 commit a528000

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,6 @@ static bool matchCallArgumentsImpl(
549549
// Record the first argument for the variadic.
550550
parameterBindings[paramIdx].push_back(*claimed);
551551

552-
// If the argument is itself variadic, we're forwarding varargs
553-
// with a VarargExpansionExpr; don't collect any more arguments.
554-
if (args[*claimed].isVariadic() ||
555-
args[*claimed].getPlainType()->is<PackExpansionType>()) {
556-
return;
557-
}
558-
559552
auto currentNextArgIdx = nextArgIdx;
560553
{
561554
nextArgIdx = *claimed;

test/Constraints/pack-expansion-expressions.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,33 @@ func callCopyAndBind<T>(_ arg: repeat each T) {
144144
// Don't propagate errors for invalid declaration reference
145145
let result = copyIntoTuple(repeat each arg)
146146
}
147+
148+
do {
149+
struct TestArgMatching {
150+
subscript<each T>(data arg: repeat each T) -> Int {
151+
get { 42 }
152+
set {}
153+
}
154+
}
155+
156+
func test_that_variadic_generics_claim_unlabeled_arguments<each T>(_ args: repeat each T, test: inout TestArgMatching) {
157+
func testLabeled<each U>(data: repeat each U) {}
158+
func testUnlabeled<each U>(_: repeat each U) {}
159+
func testInBetween<each U>(_: repeat each U, other: String) {}
160+
161+
testLabeled(data: repeat each args) // Ok
162+
testLabeled(data: repeat each args, 1) // Ok
163+
testLabeled(data: repeat each args, 1, 2, 3) // Ok
164+
165+
testUnlabeled(repeat each args) // Ok
166+
testUnlabeled(repeat each args, 1) // Ok
167+
testUnlabeled(repeat each args, 1, 2, 3) // Ok
168+
169+
testInBetween(repeat each args, 1, 2.0, other: "") // Ok
170+
171+
_ = test[data: repeat each args]
172+
_ = test[data: repeat each args, 0, ""]
173+
174+
test[data: repeat each args, "", 42] = 0
175+
}
176+
}

0 commit comments

Comments
 (0)