# Compiler issue: Escaping closure captures non-escaping parameter 'block'

**URL:** <https://forums.swift.org/t/compiler-issue-escaping-closure-captures-non-escaping-parameter-block/83578>\
**Category:** Using Swift\
**Tags:** closure, escapingclosure\
**Created:** [December 5, 2025, 11:33am UTC](https://forums.swift.org/t/compiler-issue-escaping-closure-captures-non-escaping-parameter-block/83578 "2025-12-05T11:33:48Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jamieQ](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jamieq/32/5117_2.png) [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Post date:** [December 5, 2025, 12:47pm UTC](https://forums.swift.org/t/compiler-issue-escaping-closure-captures-non-escaping-parameter-block/83578/2 "2025-12-05T12:47:56Z")

</div>

my best current guess:

```swift
func executeOk(block: () -> Void) {
    { block() }()
}

```

this one compiles because the wrapping closure is also inferred to be non-escaping. this is visible in the AST dump output (see [this](https://swift.godbolt.org/z/9djW5fhY8), and note how there is no `escaping` tag on the corresponding `closure_expr`).

```swift
 func execute1(block: () -> Void) {
    let closure = { block() }
}

```

since the closure is stored in this case, the closure's function type is escaping (variables like this currently are always escaping AFAIK – see discussion [here](https://forums.swift.org/t/is-a-closure-considered-as-non-escaping-if-its-stored-in-local-variable-and-not-passed-to-other-functions/81279/2)). but this compiles because the diagnostics check for an 'interesting' use of the escaped value, and there aren't any here.

```swift
func executeNOK(block: () -> Void) {
    let closure = { block() } // compiler issue: Escaping closure captures non-escaping parameter 'block'
    closure()
}

```

this one is similar to `execute1` but fails to compile because there is a use of the escaping closure that captures the non-escaping parameter. that's treated as a violation of the escaping rules even though in your example it's clearly not actually escaping.

* * *

IIUC, the diagnostic you hit in the final case is implemented in [DiagnoseInvalidEscapingCaptures.cpp](https://github.com/swiftlang/swift/blob/5aba778b01dd6767c85cd69f15153af0315f8687/lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp) if you're interested in the particulars. @Slava_Pestov will hopefully correct any errors in this assessment.

---

_[View the full topic](https://forums.swift.org/t/compiler-issue-escaping-closure-captures-non-escaping-parameter-block/83578)._
