[Ironruby-core] Fixnum Patch
John Messerly
jomes at microsoft.com
Wed Dec 12 18:04:58 EST 2007
Peter Bacon Darwin:
> What John discusses below was part of the reason I was wary (not
> weary!) of using Nullable types.
>
> I have now tested it and if you have a method that, for instance,
> returns int? then on the occasions that null is returned that class of
> the resulting object is NilClass and when it is not null, the class is
> Fixnum. So all seems to be well and I am happy to fix-up those methods
> in Bignum and Fixnum that should use Nullable types when I next submit
> a patch.
On second thought, it might be better to not use Nullable<int>. As Dino & Tomas pointed out, now we're playing games with our type system, because to the CLR Int32 and Nullable<Int32> are different types. For example, if you have a CLR method "foo" that returns Nullable<Int32>:
x = obj.foo # x is now a Nullable<Int32>
5 + x # this is probably okay; the method binder converts Nullable<Int32> arguments to Int32
x + 5 # how does this work? Nullable<T> doesn't define the Ruby method "+"
Since x is a Nullable<Int32>, we should be looking up method calls on Nullable<Int32>. But that won't work...
Actually, it might be a bug that it's working now. Probably better to just leave return values as "object".
- John
More information about the Ironruby-core
mailing list