Avatar
Avatar
Iceman
@swift-6.2-dev -swift-version 6 func doSomething(_: @Sendable () -> ()) { } func foo(nonsendable: Any) { @Sendable func track1() { doSomething { track1() } print(nonsendable) } @MainActor func track2() { doSomething { Task { @MainActor in track2() } } print(nonsendable) } }
exit status 1 with stderr:<stdin>:9:15: error: capture of 'nonsendable' with non-Sendable type 'Any' in a '@Sendable' local function [#SendableClosureCaptures] 7 | track1() 8 | } 9 | print(nonsendable) | `- error: capture of 'nonsendable' with non-Sendable type 'Any' in a '@Sendable' local function [#SendableClosureCaptures] 10 | } 11 | <stdin>:15:17: error: capture of 'track2()' with non-Sendable type '() -> ()' in a '@Sendable' closure [#SendableClosureCaptures] 13 | doSomething { 14 | Task { @MainActor in 15 | track2() | |- error: capture of 'track2()' with non-Sendable type '() -> ()' in a '@Sendable' closure [#SendableClosureCaptures] | `- note: a function type must be marked '@Sendable' to conform to 'Sendable' 16 | } 17 | } [#SendableClosureCaptures]: <https://docs.swift.org/compiler/documentation/diagnostics/sendable-closure-captures>