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

Parsing error on sum type with a vector payload? #1853

Closed
poeface opened this issue Jan 21, 2023 · 4 comments
Closed

Parsing error on sum type with a vector payload? #1853

poeface opened this issue Jan 21, 2023 · 4 comments

Comments

@poeface
Copy link

poeface commented Jan 21, 2023

The following code fails parsing:

type Thing = #this [2]f64 | #that [3]f64

saying

Unexpected token: '['
Expected one of the following: 

with no suggested token provided. Is this a parsing bug? I have been trying to figure out if this could be an intentional limitation on sum types, but I can't find anything in the documentation that would suggest it. If it is intentional, I apologize for filing an unnecessary issue!

@athas
Copy link
Member

athas commented Jan 21, 2023

Due to embarrassing parser restrictions, you have to parenthesize those:

type Thing = #this ([2]f64) | #that ([3]f64)

@athas
Copy link
Member

athas commented Jan 21, 2023

Actually, the parser technology in my head may have matured to the point that this can be fixed. The fix will make certain currently working (but confusing) syntax invalid, though. From the test suite, []#foo | #bar can now longer be used to indicate an array of an anonymous sum type, and [t] mpr_net [n] will not work for an array of elements of type mpr_net [n]. In both cases, the solution is to add parentheses.

@athas
Copy link
Member

athas commented Jan 21, 2023

Oh, apparently breaking that is not actually required. We might consider it some other time, though... I am horrified that we allow that.

@poeface
Copy link
Author

poeface commented Jan 21, 2023

you have to parenthesize those

ah that makes sense--that's no problem to use. Thanks for a fix all the same!

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

No branches or pull requests

2 participants