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

Compiler: fix enum overflow on non-default values #7776

Merged
merged 3 commits into from
May 14, 2019

Conversation

asterite
Copy link
Member

Fixes #7268

There's also #7271, which is slightly different, but I'll fix it in a separate PR (it's harder).

asterite added 2 commits May 13, 2019 16:29
Instead of passing `target_type` around we pass it in the constructor,
which makes much more sense (I want to interpret values with some target
type in mind).
@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels May 13, 2019
@asterite asterite force-pushed the bug/enum-overflow branch from 46b721b to 7f08ba6 Compare May 14, 2019 12:33
Copy link
Member

@bcardiff bcardiff left a comment

Choose a reason for hiding this comment

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

I'm not sure if #7271 will be fixable. I guess you are thinking in interpret the constants based on the enum target type, but that will mean that the type a constant expression will depend on the context. It can be a slippery slope from there I think.

@bcardiff bcardiff added this to the 0.29.0 milestone May 14, 2019
@asterite
Copy link
Member Author

I guess you are thinking in interpret the constants based on the enum target type

Yes, that's what we are doing right now. So if you have 1 << 40, it will work fine if the enum is defined as UInt64 but it will give an error if it's Int32. I think that makes sense, there's no point to have the user type 1_u64 << 40 when they expect to get a UInt64.

I thought to fix #7271 I just had to catch OverflowException but that doesn't seem to be the case.

@straight-shoota straight-shoota merged commit cbccc88 into crystal-lang:master May 14, 2019
@asterite asterite deleted the bug/enum-overflow branch May 14, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum that inherit UInt64 do not get right values
3 participants