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

commented May 13, 2019

Fixes #7268

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

asterite added some commits May 13, 2019

Compiler: refactor MathInterpter
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 force-pushed the asterite:bug/enum-overflow branch from 46b721b to 7f08ba6 May 14, 2019

@bcardiff
Copy link
Member

left a comment

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

This comment has been minimized.

Copy link
Member Author

commented May 14, 2019

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

5 checks passed

ci/circleci: check_format Your tests passed on CircleCI!
Details
ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@asterite asterite deleted the asterite:bug/enum-overflow branch May 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.