MerlinVR / UdonSharp

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

Assignment of constant values should not generate conversion calls #20

Open bdunderscore opened 4 years ago

bdunderscore commented 4 years ago

Describe the bug in detail: When assigning a variable from a constant, in some cases a runtime conversion is generated, instead of simply ensuring the constant is the correct type.

Provide steps/code to reproduce the bug:

uint[] x = new int[1];
x[0] = 0;

Expected behavior: What was the excepted result?

A single array set instruction should be generated. However, in fact, a conversion is generated first:

         # x[0] = 0;
        PUSH, __1_const_intnl_SystemInt32
        PUSH, __0_intnl_SystemUInt32
        EXTERN, "SystemConvert.__ToUInt32__SystemInt32__SystemUInt32"
        PUSH, __0_x_UInt32Array
        PUSH, __1_const_intnl_SystemInt32
        PUSH, __0_intnl_SystemUInt32
        EXTERN, "SystemUInt32Array.__Set__SystemInt32_SystemUInt32__SystemVoid"