# \[Accepted\] SE-0418: Inferring Sendable for methods and key path literals

**URL:** <https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242>\
**Category:** Announcements\
**Created:** [January 3, 2024, 12:16am UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242 "2024-01-03T00:16:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![beccadax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beccadax/32/34217_2.png) [@beccadax](https://forums.swift.org/u/beccadax)\
**Post date:** [January 3, 2024, 12:16am UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/1 "2024-01-03T00:16:08Z")

</div>

Hello Swift community,

The [review](https://forums.swift.org/t/se-0418-inferring-sendable-for-methods-and-key-path-literals/68999) of [SE-0418: Inferring Sendable for methods and key path literals](https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md) ran from **December 14, 2023...January 1, 2024**.

Feedback was light and focused on clarifying the proposal's scope and its interactions with other features. The steering group noted that the proposal is a little vague about the specifics of the new `appending(path:)` overloads, but the open questions concern issues like back deployment that are not within the scope of evolution reviews. Other than that, the review did not identify any cause for concern, so the Language Steering Group has chosen to **accept** the proposal.

Thank you all for your participation in this discussion!

Becca Royal-Gordon  
SE-0418 Review Manager

---

<div class="post-metadata">

**Author:** ![Nickolas\_Pohilets](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/nickolas_pohilets/32/10659_2.png) [@Nickolas\_Pohilets](https://forums.swift.org/u/Nickolas_Pohilets)\
**Post date:** [January 5, 2024, 9:25am UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/2 "2024-01-05T09:25:10Z")

</div>

I’m sorry for being late to the party, but I think I see an issue in the proposal.

For unapplied methods, sendability of the nominal type should affect sendability of result type, but not the unapplied method itself. Unapplied method, being a global function, is always sendable:

```swift
class A {
    func foo(String) -> Bool
}
struct B: Sendable {
    func foo(String) -> Bool
}

let a: @Sendable (A) -> (String) -> Bool = A.foo
let b: @Sendable (B) -> @Sendable (String) -> Bool = B.foo

```

---

<div class="post-metadata">

**Author:** ![hborla](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hborla/32/27563_2.png) [@hborla](https://forums.swift.org/u/hborla)\
**Post date:** [January 5, 2024, 6:41pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/3 "2024-01-05T18:41:03Z")

</div>

> [@Nickolas\_Pohilets](#):
>
> For unapplied methods, sendability of the nominal type should affect sendability of result type, but not the unapplied method itself. Unapplied method, being a global function, is always sendable:

Yes, you're right. The implementation of `InferSendableFromCaptures` already behaves this way, so if the proposal says otherwise, I think it's a mistake.

---

<div class="post-metadata">

**Author:** ![KeithBauerANZ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/keithbaueranz/32/27897_2.png) [@KeithBauerANZ](https://forums.swift.org/u/KeithBauerANZ)\
**Post date:** [January 10, 2024, 9:46pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/4 "2024-01-10T21:46:10Z")

</div>

Found a fun bug potentially related to this proposal, [Sendability incorrectly inferred for curried method · Issue #70829 · apple/swift · GitHub](https://github.com/apple/swift/issues/70829)

---

<div class="post-metadata">

**Author:** ![beccadax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beccadax/32/34217_2.png) [@beccadax](https://forums.swift.org/u/beccadax)\
**Post date:** [January 10, 2024, 10:03pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/5 "2024-01-10T22:03:51Z")

</div>

I think the bug here is that point 5 in the proposal is not being enforced:

> [@](#):
>
> 1. Prohibition of marking methods `@Sendable` when the type they belong to is not `@Sendable` .
> 
> ```swift
> class C {
> var random: Int = 0 // random is mutable so `C` can't be checked sendable
> 
> @Sendable func generateN() async -> Int { //error: adding @Sendable to function of non-Senable type prohibited
> random = Int.random(in: 1..<100)
> return random
> }
> }
> 
> func test(x: C) { x.generateN() }
> 
> let num = C()
> Task.detached {
> test(num)
> }
> test(num) // data-race
> 
> ```

---

<div class="post-metadata">

**Author:** ![angela-laar](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/angela-laar/32/28083_2.png) [@angela-laar](https://forums.swift.org/u/angela-laar)\
**Post date:** [January 10, 2024, 10:50pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/6 "2024-01-10T22:50:38Z")

</div>

Oh you're right @beccadax. It looks like this rule is only enforced for non-async functions.

---

<div class="post-metadata">

**Author:** ![angela-laar](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/angela-laar/32/28083_2.png) [@angela-laar](https://forums.swift.org/u/angela-laar)\
**Post date:** [January 10, 2024, 11:26pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/7 "2024-01-10T23:26:20Z")

</div>

Actually async and non-async methods should be handled by [Pull Request #69220](https://github.com/apple/swift/pull/69220/files) !

---

<div class="post-metadata">

**Author:** ![James\_Dempsey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/james_dempsey/32/14336_2.png) [@James\_Dempsey](https://forums.swift.org/u/James_Dempsey)\
**Post date:** [February 24, 2024, 3:59pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/8 "2024-02-24T15:59:40Z")

</div>

@beccadax

SE-0418 is marked as implemented in Swift 6.0.

However, it also has an upcoming feature flag defined.

Wouldn't adjusting to the source incompatibilities introduced with this proposal be part of migrating to the Swift 6 language mode?

Or is the upcoming feature flag still needed because the functionality will be in Swift 6.0, even if it is running under Swift 5 language mode? (And would therefore enable the Swift 6 language mode behavior?)

Thank you!

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [February 24, 2024, 4:18pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/9 "2024-02-24T16:18:42Z")

</div>

Correct. Swift 6.0 refers to the next release after 5.10, not the language mode. Both the Swift 5 and Swift 6 language modes will be supported in Swift 6.0. Upcoming feature flags allow piecewise migration of code between language modes.

---

<div class="post-metadata">

**Author:** ![James\_Dempsey](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/james_dempsey/32/14336_2.png) [@James\_Dempsey](https://forums.swift.org/u/James_Dempsey)\
**Post date:** [February 24, 2024, 4:57pm UTC](https://forums.swift.org/t/accepted-se-0418-inferring-sendable-for-methods-and-key-path-literals/69242/10 "2024-02-24T16:57:36Z")

</div>

Thank you for clarifying @xwu.
