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

switching on enum for Data type doesn't work as documented #109

Open
rjharmon opened this issue Nov 2, 2023 · 2 comments
Open

switching on enum for Data type doesn't work as documented #109

rjharmon opened this issue Nov 2, 2023 · 2 comments

Comments

@rjharmon
Copy link

rjharmon commented Nov 2, 2023

  foo : Data = ...
  foo.switch{ MyEnum => ... }

Error: MyEnum isn't a valid enum member of Data

foo.switch{ (index: Int, fields: Data[]) => ... } works.

Note: foo.switch{ (index: Int, _) => ... } gives a syntax error. Not sure if that's as intended.

@christianschmitz
Copy link
Contributor

This syntax error is due to the parser currently expecting at least one of Int, []Data, Map[Data]Data or ByteArray as an additional switch case in order to detect data-switch vs regular switch. I guess that doesn't work in case you're not interested in any of those cases and just want to look at enums and enum variants. I'll need some time to come up with a consistent way to handle this edge-case.

For the note: the syntax is sadly not perfectly consistent with the rest of the language, but the following should work:

foo.switch{(index: Int, []Data) => ...}

@christianschmitz
Copy link
Contributor

christianschmitz commented Nov 8, 2023

Soon I'll expose the auto-generated from_data_safe method though, which might be a better fit for your use-case:

MyEnum::from_data_safe(data) -> Option[MyEnum]

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