NETMF / llilum

Development Platform for MSIL and UWP apps targeting Micro Controllers. Part of the .NET Micro Framework family.
Other
159 stars 52 forks source link

ConstantExpression.ConvertToType is incorrect #177

Open ckarenz opened 8 years ago

ckarenz commented 8 years ago

The following code will generate a compile-time error:

                ulong source;
                float dest;
                source = 1;
                dest = source;
                if (dest == 1F)
                    return 0;
                else
                    return 1;

The conversion from source to dest (ulong to double) reinterprets the source's raw bytes as a float, resulting in the value 1.4E-45. Upon investigation, this issue is endemic to ConstantExpression and the way it converts values.

ConvertToType needs to take an object, instead of raw bytes as ulong, and have similar behavior to Convert.ChangeType. This is a relatively high-risk change.

ckarenz commented 8 years ago

Note: For a convenient repro, compiling many of the tests in BasicTests.cs will hit this issue.