Leftover Implicit Conversion Perlisms #32

dtm opened this Issue Aug 4, 2009 · 5 comments


None yet

2 participants

dtm commented Aug 4, 2009
crb(main):001:0>puts [1,2]+3

irb >> puts [1,2]+3
TypeError: can't convert Fixnum into Array
        from (irb):1:in `+'
        from (irb):1
treed commented Aug 5, 2009

To quote #9:

This is caused by the leftover Perlisms from when a lot of the originating code was taken from Rakudo. Namely: implicit conversion. Ruby doesn't do it by default. So in order to fix this, here are the steps that'll be taken:

Go through and add the implicit (to_str, to_int, etc.) and explicit (to_s, to_i, etc.) methods for all the stdlib classes that declare them. Then add stuff into Object so that anything that doesn't have an explicit implicit conversion method won't convert implicitly. This'll probably break a lot of things, but it'll at least let us know where things depend on implicit conversion. Then we go through and fix those.

treed commented Aug 8, 2009

#9 is now waitiing on this.

treed commented Aug 12, 2009

Been working on this today. Got a bunch of it done.

One problem I encountered which I don't quite understand is that removing the get_string vtable from NilClass causes cardinal.pir to not be able to instantiate a CardinalArray, because it can't find it. Might just have to live with this in until someone can figure out why that happens.

treed commented Aug 13, 2009

Another problem is that parrot;Integer declares a to_int method, whereas cardinal;Integer absolutely cannot have a to_int.

Not sure what to do about this. One might consider replacing to_int with a method that just throws an Exception, but that's still a little screwy in the case of "Hey, object, do you have a to_int method?" "Yes, yes, I do." "Sweet, I can treat you like an int." Then blammo.

So, yeah, this is a problem.

Parrot has opcodes for adding methods, but none for removing them.

treed commented Aug 15, 2009

My work so far is on the iss32 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment