# Is \`sending\` supported by variadic generics?

**URL:** <https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394>\
**Category:** Using Swift\
**Tags:** concurrency, variadic-generics\
**Created:** [September 5, 2024, 4:35pm UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394 "2024-09-05T16:35:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dehesa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dehesa/32/10911_2.png) [@dehesa](https://forums.swift.org/u/dehesa)\
**Post date:** [September 5, 2024, 4:35pm UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394/1 "2024-09-05T16:35:42Z")

</div>

I am trying to _transfer_ non-sendable variadic generics values to a function through the `sending` keyword. However, I don't seem to be able to use it correctly.

```swift
struct Runner {
  func run<each Value>(_ value: repeat each Value) async {
    // Some code here potentially transferring values as well
  }
}

```

Where should I place the `sending` keyword? Is it supported at all? I can crash the compiler fairly easily depending on the placement of the keyword.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [September 5, 2024, 5:00pm UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394/2 "2024-09-05T17:00:15Z")

</div>

The parameter packs implementation hasn’t yet caught up with the fancier things you can do with function parameters, such as inout, ownership modifiers, ~Copyable or sending.

There are some common issues in the parser with parsing these specifiers in conjunction with `repeat` which should be easy to resolve, then we can at least diagnose the unsupported cases in a clean way.

Implementing the semantics for each one is of course a separate project in itself.

---

<div class="post-metadata">

**Author:** ![mattie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mattie/32/13267_2.png) [@mattie](https://forums.swift.org/u/mattie)\
**Post date:** [September 5, 2024, 7:40pm UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394/3 "2024-09-05T19:40:55Z")

</div>

I've run into problems here as well. Please do file bugs, especially if you can cause a crash! Here are some of mine:

> <https://github.com/swiftlang/swift/issues/74484>
>
> \### Description
> 
> Having a hard time figuring out how to make parameter pack type…s \`Sendable\`.
> 
> \`\`\`
> error: capture of 'parameters' with non-sendable type 'repeat each ParameterType' in a \`@Sendable\` closure
> 5 | ) -\> @Sendable () async -\> Void where repeat each ParameterType: Sendable {
> 6 | {
> 7 | await effect(repeat each parameters)
> | \`- error: capture of 'parameters' with non-sendable type 'repeat each ParameterType' in a \`@Sendable\` closure
> 8 | }
> 9 | }
> \`\`\`
> 
> \### Reproduction
> 
> \`\`\`swift
> func doThing\<each ParameterType: Sendable\>(
> \_ effect: @Sendable @escaping (repeat each ParameterType) async -\> Void,
> with parameters: repeat each ParameterType
> ) -\> @Sendable () async -\> Void {
> {
> await effect(repeat each parameters)
> }
> }
> \`\`\`
> 
> 
> \### Expected behavior
> 
> This should compile without error.
> 
> \### Environment
> 
> Apple Swift version 6.0-dev (LLVM bf8bbb910874156, Swift a0bb875256e41ae)
> Target: arm64-apple-macosx14.0
> 
> \### Additional information
> 
> \_No response\_

> <https://github.com/swiftlang/swift/issues/74688>
>
> \### Description
> 
> This code seems like it should be exactly the kind of thing tha…t region-based isolation can prove is race-free.
> 
> \`\`\`
> test.swift:13:20: error: sending 'self'-isolated value of type 'Int' with later accesses to actor-isolated context risks causing data races
> 11 | let value = 10
> 12 | 
> 13 | await fooActor.message(value)
> | \`- error: sending 'self'-isolated value of type 'Int' with later accesses to actor-isolated context risks causing data races
> 14 | }
> 15 | 
> \`\`\`
> 
> \### Reproduction
> 
> \`\`\`swift
> actor FooActor\<each T\> {
> var messages: \[(repeat each T)\] = \[\]
> 
> func message(\_ num: repeat each T) {
> messages.append((repeat each num))
> }
> }
> 
> func foo() async {
> let fooActor = FooActor\<Int\>()
> let value = 10
> 
> await fooActor.message(value)
> }
> \`\`\`
> 
> 
> \### Expected behavior
> 
> I would expect this to compile without error.
> 
> \### Environment
> 
> Apple Swift version 6.0-dev (LLVM 5b37bd4c1c578e9, Swift 54898ce105c7185)
> Target: arm64-apple-macosx14.0
> 
> \### Additional information
> 
> \_No response\_

---

<div class="post-metadata">

**Author:** ![dehesa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dehesa/32/10911_2.png) [@dehesa](https://forums.swift.org/u/dehesa)\
**Post date:** [September 6, 2024, 8:33am UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394/4 "2024-09-06T08:33:57Z")

</div>

That is good to know. Thank you @Slava_Pestov

---

<div class="post-metadata">

**Author:** ![dehesa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dehesa/32/10911_2.png) [@dehesa](https://forums.swift.org/u/dehesa)\
**Post date:** [September 6, 2024, 8:35am UTC](https://forums.swift.org/t/is-sending-supported-by-variadic-generics/74394/5 "2024-09-06T08:35:39Z")

</div>

That is a good point @mattie. Thank you for the remainder. [Here it is](https://github.com/swiftlang/swift/issues/76306).
