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

Fix grammar issues #915

Merged
merged 8 commits into from
May 4, 2023
Merged

Conversation

JohnnyMorganz
Copy link
Contributor

@JohnnyMorganz JohnnyMorganz commented May 2, 2023

  • The type list for function declarations does not accept defaults, but the grammar incorrectly allowed this.
  • Allow the empty table type {}
  • Allow composite types and types surrounded by parentheses (e.g. string??, (string), (string | number) & boolean)

The type list for function declarations does not accept defaults,
but the grammar incorrectly allowed this
@JohnnyMorganz JohnnyMorganz changed the title Fix generic type list grammar for func defs Fix grammar for generic type lists and table type May 2, 2023
docs/_pages/grammar.md Outdated Show resolved Hide resolved
@JohnnyMorganz JohnnyMorganz changed the title Fix grammar for generic type lists and table type Fix grammar issues May 2, 2023
Comment on lines 78 to 79
GenericTypePackParameterWithDefault = NAME '...' ['=' (TypePack | VariadicTypePack | GenericTypePack)]
GenericTypeListWithDefaults = NAME ['=' Type] [',' GenericTypeListWithDefaults] | GenericTypePackParameterWithDefault {',' GenericTypePackParameterWithDefault}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still actually slightly wrong. It does not encode that after one generic is specified with a default, then all other generics must also have a default. It currently allows something like <X = string, Y, Z... = ...string, P...>.

Something like the following may be better:

Suggested change
GenericTypePackParameterWithDefault = NAME '...' ['=' (TypePack | VariadicTypePack | GenericTypePack)]
GenericTypeListWithDefaults = NAME ['=' Type] [',' GenericTypeListWithDefaults] | GenericTypePackParameterWithDefault {',' GenericTypePackParameterWithDefault}
GenericTypePackParameterWithDefault = NAME '...' '=' (TypePack | VariadicTypePack | GenericTypePack)
GenericTypeListWithDefaults =
GenericTypeList |
NAME {',' NAME} {',' NAME '=' Type} {',' GenericTypePackParameterWithDefault} |
NAME '=' Type {',' GenericTypePackParameterWithDefault} |
GenericTypePackParameterWithDefault {',' GenericTypePackParameterWithDefault}

But is it the simplest it can be? I think it covers everything

@vegorov-rbx vegorov-rbx self-requested a review May 2, 2023 19:57
docs/_pages/grammar.md Outdated Show resolved Hide resolved
Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
@vegorov-rbx vegorov-rbx merged commit 5891de6 into luau-lang:master May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants