Skip to content

Commit a35949c

Browse files
committed
test: Decouple each placement test cases
1 parent 8e0bcfa commit a35949c

File tree

1 file changed

+77
-81
lines changed

1 file changed

+77
-81
lines changed

test/Constraints/pack-expansion-expressions.swift

Lines changed: 77 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -263,50 +263,6 @@ func forwardFunctionPack<each T>(functions: repeat (each T) -> Bool) {
263263
takesFunctionPack(functions: repeat each functions)
264264
}
265265

266-
func packOutsideExpansion<each T>(
267-
t: repeat each T,
268-
t2: repeat (each T)?,
269-
t3: repeat () -> each T
270-
) {
271-
_ = t
272-
// expected-error@-1{{value pack 'each T' must be referenced with 'each'}}
273-
274-
forward(t)
275-
// expected-error@-1{{value pack 'each T' must be referenced with 'each'}}
276-
277-
_ = each t
278-
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
279-
280-
forward(each t)
281-
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
282-
283-
let tuple = (repeat each t)
284-
285-
_ = tuple
286-
287-
_ = each tuple
288-
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
289-
290-
// https://github.com/swiftlang/swift/issues/78393
291-
let _ = (t2)
292-
// expected-error@-1{{value pack '(each T)?' must be referenced with 'each'}}
293-
let _ = t3
294-
// expected-error@-1{{value pack '() -> each T' must be referenced with 'each'}}
295-
}
296-
297-
do {
298-
// FIXME: https://github.com/swiftlang/swift/issues/78426
299-
func f<each T>(_: (repeat each T) -> (repeat each T)) {}
300-
// expected-error@+2 {{cannot infer type of closure parameter 'x' without a type annotation}}
301-
// expected-error@+1 {{cannot convert value of type '(Int, Int)' to closure result type '(_: _)'}}
302-
f { x in
303-
// Once this issue is fixed, verify that 'x' below is diagnosed correctly.
304-
// If it is not, please reopen https://github.com/swiftlang/swift/issues/78393.
305-
let _ = x
306-
return (1, 2)
307-
}
308-
}
309-
310266
func identity<T>(_ t: T) -> T { t }
311267
func concrete(_: Int) {}
312268

@@ -497,18 +453,6 @@ do {
497453
}
498454
}
499455

500-
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without a type annotation`
501-
do {
502-
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat (each T).A) {
503-
return (repeat (each value).makeA()) // Ok
504-
}
505-
506-
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat (each T).A) {
507-
return (repeat each value.makeA())
508-
// expected-error@-1 {{value pack 'each T' must be referenced with 'each'}} {{25-25=(each }} {{30-30=)}}
509-
}
510-
}
511-
512456
// rdar://107835215 - failed to produce a diagnostic for invalid pack expansion expression
513457
do {
514458
func test1(x: Int) {
@@ -532,19 +476,6 @@ do {
532476
}
533477
}
534478

535-
// missing 'each' keyword before value pack references
536-
do {
537-
func overloaded<each U>(_: String, _: repeat each U) -> Int { 42 }
538-
func overloaded<each T>(_: Int, _ b: repeat each T) -> (repeat each T) {
539-
fatalError()
540-
}
541-
542-
func test<each T>(v: repeat each T) {
543-
_ = (repeat overloaded(42, v)) // expected-error {{value pack 'each T' must be referenced with 'each'}} {{32-32=each }}
544-
_ = (repeat overloaded(42, each v)) // Ok
545-
}
546-
}
547-
548479
// rdar://108904190 - top-level 'repeat' not allowed in single-expression closures
549480
func test_pack_expansion_to_void_conv_for_closure_result<each T>(x: repeat each T) {
550481
let _: () -> Void = { repeat print(each x) } // Ok
@@ -738,18 +669,6 @@ do {
738669
}
739670
}
740671

741-
// rdar://110847476 - unrelated assignment and raw representable diagnostics
742-
do {
743-
struct Test<each Base: AsyncSequence> {
744-
let base: (repeat each Base)
745-
746-
init(base: repeat each Base) {
747-
self.base = base
748-
// expected-error@-1 {{value pack 'each Base' must be referenced with 'each'}}
749-
}
750-
}
751-
}
752-
753672
// Pack Iteration
754673
do {
755674
func test<each T>(_ t: repeat each T) {
@@ -788,3 +707,80 @@ func butt<T>(x: T) {}
788707
func rump<each T>(x: repeat each T) {
789708
let x = (repeat { butt(each x) }()) // expected-error {{missing argument label 'x:' in call}}
790709
}
710+
711+
// Placement of `each` in expressions.
712+
do {
713+
do {
714+
func overload<each U>(_: String, _: repeat each U) -> Int {}
715+
func overload<each T>(_: Int, _ b: repeat each T) -> (repeat each T) {}
716+
717+
func test<each T>(
718+
t: repeat each T,
719+
t2: repeat (each T)?,
720+
t3: repeat () -> each T
721+
) {
722+
_ = t
723+
// expected-error@-1{{value pack 'each T' must be referenced with 'each'}}
724+
725+
forward(t)
726+
// expected-error@-1{{value pack 'each T' must be referenced with 'each'}}
727+
728+
_ = each t
729+
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
730+
731+
forward(each t)
732+
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
733+
734+
let tuple = (repeat each t)
735+
_ = tuple
736+
_ = each tuple
737+
// expected-error@-1{{pack reference 'each T' can only appear in pack expansion}}
738+
739+
// https://github.com/swiftlang/swift/issues/78393
740+
let _ = (t2)
741+
// expected-error@-1{{value pack '(each T)?' must be referenced with 'each'}}
742+
let _ = t3
743+
// expected-error@-1{{value pack '() -> each T' must be referenced with 'each'}}
744+
745+
let _ = (repeat overload(42, t)) // expected-error {{value pack 'each T' must be referenced with 'each'}} {{36-36=each }}
746+
let _ = (repeat overload(42, each t)) // Ok
747+
}
748+
}
749+
750+
// FIXME: https://github.com/swiftlang/swift/issues/78426
751+
do {
752+
func f<each T>(_: (repeat each T) -> (repeat each T)) {}
753+
// expected-error@+2 {{cannot infer type of closure parameter 'x' without a type annotation}}
754+
// expected-error@+1 {{cannot convert value of type '(Int, Int)' to closure result type '(_: _)'}}
755+
f { x in
756+
// Once this issue is fixed, verify that 'x' below is diagnosed correctly.
757+
// If it is not, please reopen https://github.com/swiftlang/swift/issues/78393.
758+
let _ = x
759+
return (1, 2)
760+
}
761+
}
762+
763+
// rdar://107675464 - misplaced `each` results in `type of expression is ambiguous without a type annotation`
764+
do {
765+
func test_correct_each<each T: P>(_ value: repeat each T) -> (repeat (each T).A) {
766+
return (repeat (each value).makeA()) // Ok
767+
}
768+
769+
func test_misplaced_each<each T: P>(_ value: repeat each T) -> (repeat (each T).A) {
770+
return (repeat each value.makeA())
771+
// expected-error@-1 {{value pack 'each T' must be referenced with 'each'}} {{27-27=(each }} {{32-32=)}}
772+
}
773+
}
774+
775+
// rdar://110847476 - unrelated assignment and raw representable diagnostics
776+
do {
777+
struct Test<each Base: AsyncSequence> {
778+
let base: (repeat each Base)
779+
780+
init(base: repeat each Base) {
781+
self.base = base
782+
// expected-error@-1 {{value pack 'each Base' must be referenced with 'each'}}
783+
}
784+
}
785+
}
786+
}

0 commit comments

Comments
 (0)