Skip to content

[Swift 6.1] Availability validation is broken in a certain case #80338

Open
@DmT021

Description

@DmT021

Description

No response

Reproduction

struct Foo {
  @available(macOS 15, *)
  var bar: Int { 42 }
}

func test(_ foo: Foo) {
  let x = {
    if #available(macOS 15, *) {
      foo.bar  // 'bar' is only available in macOS 15 or newer
    } else {
      nil
    }
  }() ?? 0
}

If we remove ?? 0, or if we add : Int to the variable, the error is gone.

Expected behavior

Compiles

Environment

Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

Labels

#availableFeature → statements: Availability conditionbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfswift 6.1swift 6.2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions