Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar missing optional parens for type identifiers in type inheritance clause #299

Open
sarahcantohyatt opened this issue Apr 25, 2024 · 0 comments

Comments

@sarahcantohyatt
Copy link
Contributor

Location

https://github.com/apple/swift-book/blob/main/TSPL.docc/ReferenceManual/Types.md?plain=1#L1279

Description

The grammar does not currently allow for parenthesized type identifiers in type inheritance clauses.

Current grammar:

type-inheritance-clause → : type-inheritance-list
type-inheritance-list → attributes? type-identifier | attributes? type-identifier , type-inheritance-list

Program that isn't derivable with current grammar:

protocol DefaultItem {}

protocol Item: (DefaultItem) {}

This applies to type inheritance clauses in general.
See an example with class inheritance:

class Class {}

class OtherClass: (Class) {}

Correction

Restructure the grammar to allow for parenthesized type identifiers in type inheritance classes.
Possible Solution:

type-inheritance-clause → : type-inheritance-list
type-inheritance-list → attributes? type-identifier | attributes? ( type-identifier ) | attributes? type-identifier , type-inheritance-list | attributes? ( type-identifier ), type-inheritance-list

This is just one solution but there are other, possibly cleaner, options.
Can also consider changing the productions for type to allow:
type -> type-identifier
along with
type -> (type-identifier)
This is cleaner but would allow any type-identifier to be parenthesized which may cause unintended side effects in other areas of the language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant