MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Conversion from Signed Integer Type / ja:符号付き整数型からの変換 #48

Open ikuko opened 4 years ago

ikuko commented 4 years ago

Describe the bug in detail: The behavior of C# and U# is different when you do an explicit cast. (ja: ) 明示的キャストを行った際にC#とU#で動作が異なります

Provide steps/code to reproduce the bug: C# or U# code
(ja:) C#もしくはU#のコード

int value = -1;
Debug.Log($"value: {value}");
var converted = (uint)value;// This is where Udon stops working!
Debug.Log($"converted: {converted}");

An excerpt of the problematic part of UAssembly
(ja:) 問題のある部分のUAssemblyを抜粋

 # var converted = (uint)value;
PUSH, __2_value_Int32
PUSH, __2_intnl_SystemUInt32
EXTERN, "SystemConvert.__ToUInt32__SystemInt32__SystemUInt32"
PUSH, __2_intnl_SystemUInt32
PUSH, __2_converted_UInt32
COPY

Expected behavior: If you follow C#, this U# code will be displayed in the console like this (ja:) C#に従うならばこのU#コードはコンソールに以下のように表示します

value: -1
converted: 4294967295

Explicit casts to the form of using methods such as Convert.ToUInt32 It is due to compiling. However, due to the way U# and Udon work, this may be an inevitable glitch. I wish there is a good solution, but I think it's difficult to fix. It would be better to present it as a specification in README. (ja:) 明示的キャストをConvert.ToUInt32のようなメソッドを使用する形にコンパイルすることが原因です。 しかしながらU#とUdonの仕組み上これは仕方ない不具合かもしれません。 何かしら良い解決策があれば良いのですが、修正は難しいと思います。 READMEなどで仕様として提示すると良いでしょう。

MerlinVR commented 4 years ago

Yeah this is known thing that I can't do much about without adding a chunk of overhead to numeric casts since Udon doesn't provide a way to cast for "real" right now and Convert functions are checked. I'll add a note about this to the README, but this behavior will change to be unchecked when VRC implements proper numeric casting.

Some relevant cannys for this: https://vrchat.canny.io/vrchat-udon-closed-alpha-feedback/p/provide-an-instruction-that-does-not-automatically-reassign-the-strongbox-type-w https://vrchat.canny.io/vrchat-udon-closed-alpha-feedback/p/cast-nodes

ikuko commented 4 years ago

Thanks, I voted for canny.