swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.76k stars 162 forks source link

Conflicting Contexts for API Availability between Language Guide and Language Reference #276

Open tadbyt opened 9 months ago

tadbyt commented 9 months ago

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/controlflow#Checking-API-Availability https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements#Availability-Condition

Description

In the Language Guide Checking API Availability subsection, at the beginning of the third paragraph the text states:

You can use an availability condition in an if or guard statement to conditionally execute a block of code, depending on whether the APIs you want to use are available at runtime.

All subsequent text and examples in the subsection support this.

In the Language Reference Availability Condition subsection, the first paragraph reads:

An availability condition is used as a condition of an if, while, and guard statement to query the availability of APIs at runtime, based on specified platforms arguments.

The grammar is sufficiently vague as to permit an API availability check in these and many other locations, where it doesn't appear to be semantically allowed.

Xcode doesn't yield diagnostics when an API availability is given in a while statement, but does for a repeat-while statement.

Correction

Reword the first sentence in the Language Guide Checking API Availability subsection to read:

You can use an availability condition in an if, guard, or while statement to conditionally execute a block of code, depending on whether the APIs you want to use are available at runtime.

An example shouldn't be necessary as using an API availability check is an unlikely occurance.