Skip to content

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

@sarahcantohyatt

Description

@sarahcantohyatt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions