Mysterious syntax in closure head

I have stumbled on a mysterious syntax, which I don't understand.

Given

func f (u: @MainActor @Sendable @escaping (Int) -> Int) async {
   let v = await u (Int.random (in: 0..<1024))
   print ("f (\(v)) =", Int.random (in: 0...v))
}

// Mysterious syntax: `(x: Fubar)`
//
await f {
    @MainActor(x: Fubar) x in
        Int.random (in: 0...x)
}

That code compiles, but what does (x: Fubar) mean in the closure's head?

In fact, I can replace x:Fubar with y + pi, z, g (x), w: T and the code still compiles.

await f {
    @MainActor(y + pi, z, g (x), w: T) x in
        Int.random (in: 0...x)
}

PS: I am using Xcode Version 26.5 (17F42).

I think this is just a fun little parser quirk when actor annotations are used in a closure signature, since you'll get an error if you try to do that sort of thing in other positions. This was reported a while back. The contents of the annotation parameter don't seem to make it into the parser or AST dump, so I'm assuming they're just ignored (though have not checked).

3 Likes
typealias Reply = @MainActor(
  "In retrospect I realize I could have replied to the question like this 😉"
) () -> Void
3 Likes