You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System::Char binds to double/float via to_f (0.0) but to decimal as its code point #153
A System::Char passed to a numeric CLR parameter is converted three different ways depending on the parameter type:
parameter
System::Char.new('a')
System::Char.new('5')
System::Char.MaxValue
int
TypeError
TypeError
TypeError
double, float
0.0
5.0
0.0
decimal
97
53
65535
int follows the rule in Converter.Generated.cs ("System::Char is treated like a single-character string and not a numeric type"): no conversion.
double/float go through ConvertToFloatingPointAction: no implicit conversion applies, so the protocol calls Char#to_f, the lenient String#to_f. A non-digit char silently becomes 0.0. A Ruby String passed to the same parameter goes through the strict Float() parse and raises ArgumentError for 'a'.
decimal has no Ruby protocol conversion, so the DLR's numeric char→decimal conversion applies and gives the code point.
The old Tests/Interop/net/method/binding/numeric_and_string_spec.rb expected the code point for Double, Single and Decimal (and no Int32 binding), and tagged Double/Single as failing in 2009. They still fail.
Pick one rule. Either Char is numeric for floating-point and decimal parameters, as in C#, or it is string-like everywhere: TypeError, or the strict Float() parse for floating-point, the same as a String. Then make all three agree. Silently getting 0.0 is the worst of the options.
Found while porting the binding matrices for #144; ClrInterop_BindingNumericAndString1 leaves these rows out and names this issue.
Activity