Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: numerical enum comparison #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuta-game-music
Copy link

@yuta-game-music yuta-game-music commented Apr 23, 2023

Currently, U# doesn't allow us to directly compare enum variable with number like:

EnumHoge fuga = EnumHoge.Fuga;
var comp = fuga >= 3;

When EnumHoge.Fuga is 1, our expected result is comp=false, but the current implementation transcodes like: var comp = fuga != 3;
which leads comp to be TRUE.

Note that this phenomenon doesn't occur when you write enum in the comparison code like: var comp = HogeEnum.Fuga >= 3;
because HogeEnum.Fuga is transcoded to const 1, which makes the >= operation int>=int.

This change let you appropreately convert fuga >= 3 as it is.

Currently, U# doesn't allow us to directly compare enum variable with number like:

EnumHoge fuga = EnumHoge.Fuga;
var comp = fuga >= 3;

When EnumHoge.Fuga is 1, our expected result is comp=false, but the current implementation transcodes like:
var comp = fuga != 3;
which leads comp to be TRUE.

Note that this phenomenon doesn't occur when you write enum in the comparison code like:
var comp = HogeEnum.Fuga >= 3;
because HogeEnum.Fuga is transcoded to const -1, which makes the >= operation int>=int.

This change let you appropreately convert fuga >= 3 as it is.
@github-actions
Copy link

github-actions bot commented Apr 23, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@yuta-game-music
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@yuta-game-music yuta-game-music changed the title numerical enum comparison fix: numerical enum comparison Apr 23, 2023
@yuta-game-music
Copy link
Author

This will fix #68

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant