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

Type Alias grammar is confusing #1389

Open
harudagondi opened this issue Aug 8, 2023 · 1 comment
Open

Type Alias grammar is confusing #1389

harudagondi opened this issue Aug 8, 2023 · 1 comment

Comments

@harudagondi
Copy link

At the top, the grammar is written as:

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? ( = Type WhereClause?)? ;

I assumed this applies to every instance of a type alias, but it's not. For example, type aliases are not allowed to have no type specified when declared as a top level item, but it is when as an associated type in a trait.

This is mentioned in the later paragraphs, however:

A type alias, when not used as an associated type, must include a Type and may not include TypeParamBounds.

A type alias, when used as an associated type in a trait, must not include a Type specification but may include TypeParamBounds.

A type alias, when used as an associated type in a trait impl, must include a Type specification and may not include TypeParamBounds.

This is confusing for me. I think it would be better if there was a syntax box like the one mentioned above for each case where a type alias can be found. So for example, these would be the syntax boxes for each:

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? = Type WhereClause? ;

Syntax
TypeAlias :
type IDENTIFIER GenericParams? : TypeParamBounds WhereClause? ;

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? = Type WhereClause? ;

@gdennie
Copy link

gdennie commented Oct 28, 2023

Perhaps they should be called different names:
"type alias"
and
"associated type alias"

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

2 participants