swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.72k stars 159 forks source link

Grammar does not allow for `: Self.someStaticMember` #293

Open jansorg opened 5 months ago

jansorg commented 5 months ago

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/types#Type-Identifier

Description

The grammar accepts a type annotation like : SomeType.SubSequence, but does not accept : Self.SubSequence.

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/types#Self-Type mentions that something like Self.someStaticMember is valid:

Writing Self.someStaticMember to access a member of the current type is the same as writing type(of: self).someStaticMember.

The currently grammar only accepts identifier as first token of a type-identifier, but IMHO it should accept Self to allow for Self.someStaticMember. If I understood the grammar rules correctly, then Self is always a keyword in Self.someStaticMember and thus not covered by identifier in the rule below.

type → type-identifier
...
type-identifier → type-name generic-argument-clause? | type-name generic-argument-clause? . type-identifier
type-name → identifier

Correction

No response