# \#unavailable control flow requires else?

**URL:** <https://forums.swift.org/t/unavailable-control-flow-requires-else/82809>\
**Category:** Using Swift\
**Tags:** availability\
**Created:** [October 22, 2025, 9:21pm UTC](https://forums.swift.org/t/unavailable-control-flow-requires-else/82809 "2025-10-22T21:21:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wes1](https://avatars.discourse-cdn.com/v4/letter/w/848f3c/32.png) [@wes1](https://forums.swift.org/u/wes1)\
**Post date:** [October 22, 2025, 9:21pm UTC](https://forums.swift.org/t/unavailable-control-flow-requires-else/82809/1 "2025-10-22T21:21:53Z")

</div>

`#unavailable` seems to require an else clause for the available-availing code, which creates unnecessary indentation; as a precondition, there’s typically a lot of code affected.

It would be nice if the control-transfer statements like return or continue would result in the block being recognized as available.

It’s written up as \< [Availability control flow requires if/else · Issue #85061 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/issues/85061) \>

```swift
enum Demo {
  @available(macOS 26.0, *)
  static func new26() {}
  static func f() {
    if #unavailable(macOS 26.0) {
      // report errors, etc.
      return
    }
    // ok: else { new26() }
    // Compiler error: 'new26()' is only available in macOS 26.0 or newer
    new26() 
  }
}

```

Is there a reason for this? Am I missing some logic?

I’m starting to use `#unavailable` a lot and surprised if this hasn’t come up since it was introduced. But then searching for it on github swift files, I see very few usages. hmm.

---

<div class="post-metadata">

**Author:** ![tshortli](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tshortli/32/15850_2.png) [@tshortli](https://forums.swift.org/u/tshortli)\
**Post date:** [October 22, 2025, 10:26pm UTC](https://forums.swift.org/t/unavailable-control-flow-requires-else/82809/2 "2025-10-22T22:26:26Z")

</div>

The compiler can't make any guarantees about the OS runtime version the code after the `if`. I think you must be assuming that the compiler takes the presence of the `return` statement into account, but it doesn't. To communicate the invariant you want to the compiler, you need to use a `guard` statement, which guarantees structurally that the following code is unreachable if the condition does not hold.

```swift
enum Demo {
  @available(macOS 26.0, *)
  static func new26() {}
  static func f() {
    guard #available(macOS 26.0, *) else {
      // report errors, etc.
      return
    }
    new26() // OK
  }
}

```
