swift-book icon indicating copy to clipboard operation
swift-book copied to clipboard

`os()` platform condition incorrectly defined in prose and language grammar

Open grynspan opened this issue 1 year ago • 3 comments

Location

https://github.com/swiftlang/swift-book/blob/d29368733ef0b2852c711a772b383cbfbb9b4740/TSPL.docc/ReferenceManual/Statements.md?plain=1#L1007 https://github.com/swiftlang/swift-book/blob/d29368733ef0b2852c711a772b383cbfbb9b4740/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md?plain=1#L701

Description

The lists of valid OS names used with os() are incomplete, as the language supports a variety of other OS names such as WASI and FreeBSD.

Correction

We should either leave the list open-ended, or try to comprehensively list everything the compiler supports.

It's also worth noting that if a developer passes some unsupported OS name, it's not a compiler error—the compiler will accept it, emit a warning, and just ignore the code as if it said false instead of os(whatever). So perhaps the grammar should reflect that, if possible.

grynspan avatar Jan 06 '25 16:01 grynspan

TSPL documents only the platforms that have official support. If some are missing, yes we should add them.

For additional discussion, please see https://github.com/swiftlang/swift-book/pull/225 and https://github.com/swiftlang/swift-book/issues/245.

amartini51 avatar Jan 06 '25 22:01 amartini51

The grammar of the language allows for additional values even if they're not actually supported.

grynspan avatar Jan 06 '25 23:01 grynspan

It would be sufficient to adjust the formal grammar to allow for any identifier token, with a comment to the effect of "these are the supported values; other values will compile but produce diagnostics".

grynspan avatar Jan 06 '25 23:01 grynspan