This project is read-only.
1
Vote

Roslyn doesn't respect additional static implicit operators on decimal in Script#

description

This is a cross-post of this Connect issue: https://connect.microsoft.com/VisualStudio/feedback/details/1000442/roslyn-doesnt-respect-static-implicit-conversions-in-script

Script# defines implicit conversions between Number and decimal. The Roslyn compiler in preview complains that decimal is not a valid Number.

See the attached project for repro.


Update:

I did some digging and found that this is caused by an optimization that ignores user defined implicit conversions only on decimal (UserDefinedConversions.cs):
// The decimal type does not contribute its user-defined conversions to the mix; though its 
            // conversions are actually implemented via user-defined operators, we logically treat it as 
            // though those conversions were built-in.  

            if (type.IsClassType() || type.IsStructType() && type.SpecialType != SpecialType.System_Decimal)
            {
                var namedType = (NamedTypeSymbol)type;
                if (!excludeExisting || !HasIdentityConversionToAny(namedType, result))
                {
                    result.Add(namedType);
                }
            }
This seems like an odd optimize but since it is limited to ignoring only the user-defined conversions on decimal, the workaround is to cast the decimal to a float and then the implicit conversion to Number is properly picked up.

file attachments

comments

pgavlin wrote Jan 14, 2015 at 8:14 PM

This was fixed with commit d24e504.