For the moment I have removed the crazier coercion support. It's
something that we could probably enable in pure Ruby code or that
could be provided by the "new" coercion protocols in the future, but
for now it was a bunch of specialized logic that didn't fit other
coercion protocols in the rest of the system.

The commit is in rb03e892 if anyone wants to see what's changed.
Basically, you will no longer be able to do something like the
following examples:

[0,1,0,0,1,0,1,1,0, nil, 0, 1].to_java :boolean
["true", "false", "true", "true"].to_java :boolean
[1,2,3,4,5].to_java :string
["1", "2", "3"].to_java :int
[5_000_000, 6_000_000].to_java :byte
[1, "2", :three].to_java :int
[true, "false", 1, nil].to_java :boolean

And so on. These are unnatural conversions that I don't believe should
ever have worked, and if people really want them they can add them in
Ruby (with some difficulty now and hopefully no difficulty in the
future).

Removing them brings almost all coercion logic in line. We'll be ready
for 1.5 to replace that logic with a fully Rubified version.

On Wed, Sep 23, 2009 at 4:43 PM, Charles Oliver Nutter
<[email protected]> wrote:
> Back when we were making some improvements to Java Integration's Java
> array support, a bunch of additional coercions were added. Most of
> these are tested by test/testJavaArraySupport.rb.
>
> Put simply, for many/most core Ruby types, there are several ways to
> get them to fit into a target Java type. For a target type of
> java.lang.Boolean, for example, booleans and nil obviously fit, but
> Fixnums also fit (== 0 or not), Strings fit (Boolean.valueOf(string)),
> and objects that implement to_i fit in the same way that Fixnums fit.
> For other target types, there are similar checks and implicit
> coercions.
>
> I'm thinking of removing most of these. An array of Fixnums is not an
> array of Booleans, and I don't think it's a valid implicit coercion to
> allow it to become one. The same argument goes for Strings converting
> to numerics or Booleans converting to numbers. The conversion is
> unexpected, in my opinion, and also makes the logic for inserting
> elements into an array much more complicated.
>
> My question: Is anyone using these implicit coercions of array
> elements? So far the only place I've found failures (when I just use
> "simple" coercion) is in this test script...
>
> - Charlie
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to