vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
461 stars 50 forks source link

fix: numerical enum comparison #123

Open yuta-game-music opened 1 year ago

yuta-game-music commented 1 year ago

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[bot] commented 1 year ago

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

yuta-game-music commented 1 year ago

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

yuta-game-music commented 1 year ago

This will fix #68