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

Add support for enums with negative discriminants #4204

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RunDevelopment
Copy link
Contributor

fixes #2313

This adds support for enums with negative discriminants and slightly improves error messages.

Honestly, implementing this was pretty simple. I don't have too much to say about this, just a few notes on implementation details:

  1. Within the serialized data for ASTs and descriptors, variants are still passed around as u32. Instead of representing the actual value, they now represent the bits of the i32 or u32 value. Which one it is depends on the new signed: bool field. I wanted to use i64, but this doesn't work well with inform or other serialization, so I opted to "decode" the variant values to i64 on the CLI side just before JS code gen.

  2. Holes. The parser now makes the assumption that there are <2^31 variants to make it easier to find holes. This also has the nice property that signedness does not affect the hole, which makes working with them a lot easier. In fact, I didn't even have to change any of the code for enum holes.

    This is technically a breaking change, but, you know, who has that many variants anyway?

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

Successfully merging this pull request may close these issues.

A negative custom discriminant in a fieldless number enumeration seems unsupported
1 participant