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

Generic type parameter values with parenthese types cause invalid syntax #170

Open
jeparlefrancais opened this issue Dec 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jeparlefrancais
Copy link
Contributor

jeparlefrancais commented Dec 22, 2023

When processing a type like this:

type _fieldDefStack = Array<GraphQLField<any, any>? | NULL>

Darklua currently adds parentheses around GraphQLField<any, any>? which creates invalid syntax:

type _fieldDefStack = Array<(GraphQLField<any, any>?) | NULL> -- invalid in Luau!

This is odd because the syntax defines type params as:

TypeParams = (Type | TypePack | VariadicTypePack | GenericTypePack) [',' TypeParams]

Which makes (GraphQLField<any, any>?) | NULL a valid type. Luau also agrees that this is correct syntax, as it accepts this type declaration:

type _fieldDefStack = (GraphQLField<any, any>?) | NULL

It seems like the fix for this would be to wrap the type params values in a parenthese when they contain a type union or intersection where the left side type is a parenthese type. Weirdly specific thing to add, but I think it'll do it.

@jeparlefrancais
Copy link
Contributor Author

Another fix for this is also to not add parentheses around the left side of the union, but this only works if the inner type is compatible with the union (or intersection).

@jeparlefrancais jeparlefrancais added the bug Something isn't working label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant