Skip to content

fix: numerical enum comparison#123

Open
yuta-game-music wants to merge 1 commit into
vrchat-community:masterfrom
yuta-game-music:patch-1
Open

fix: numerical enum comparison#123
yuta-game-music wants to merge 1 commit into
vrchat-community:masterfrom
yuta-game-music:patch-1

Conversation

@yuta-game-music

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

Copy link
Copy Markdown

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

github-actions Bot commented Apr 23, 2023

Copy link
Copy Markdown

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

@yuta-game-music

Copy link
Copy Markdown
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
Copy Markdown
Author

This will fix #68

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.

1 participant