|
|
|
[
Permlink
| « Hide
]
Marcin Mielzynski - 17/Jun/07 03:22 PM
Shall it fail with NoMethodError or silently return false when to_ary not supplied for non Array arguments ?
Please re-test against trunk, 1.0 branch...if it's still an issue, we should fix it on both.
It's fixed in 1.1. Dunno about 1.0, since I don't have that version any longer.
Marcin, it should just return false. As a rule, boolean methods don't raise an error in MRI on an dumb comparison. They just return false. It doesn't appear to be fixed in 1.1 for me. I hate diverging from MRI, even for bugs, but this one seems safe. I'll try to make the change now.
It's a simple patch. I just called to_ary on the RHS object before comparing it (only if it responses to "to_ary")
Hmm, the patch is ok as it matches Daniel's intentions but it breaks following test:
def test_ary Which assumes that having to_ary method is enough and then it goes for "==" comparison (but not on to_ary result, just on the argument itself). Bumping off 1.0.2 since we don't have a safe, working patch.
It seems the patch work to me. I am not an expert in Ruby, so I'm still not sure what is the issue that Marcin mentioned.
From reading through the description of the bug it seems the expected behavior is when an array is test for equal against an object and the object has to_ary then it should compare against the result of the to_ary. In the test_ary that Marcin mentioned being broken by the patch, I see 2 possibilites. 2. Marcin mentioned that having to_ary method is enough and it should go for "==" comparison which I assume he expected the assertion to return true because it was defined in def o.==(o); true; end. But the definition is a singleton method for 'o' while the assertion is calling [].==(o) which will call '==' method of Array. If I assumed Marcin correctly, then the assertion should be assert_equal(true, o.==([])) One thing is sure, MRI is wrong, and we've followed MRI writing Array implementation. The puzzling thing is why MRI tests rely on such weird behavior.
Take a look at to_ary Rubinius implementation: http://git.rubini.us/?p=code;a=blob;f=kernel/core/array.rb;h=91ca08c67ca1ef7fe48ea81746c0c6cb8ed76022;hb=HEAD I'd opt for changing the test and applying the patch. Ok, this is going to stay bumped off 1.0.2, since the patch doesn't apply cleanly and I don't have time to monkey with it. I concur about changing the test and going with the patch, if that's appropriate. Can someone prepare patches for trunk and 1.0 branch that will do this?
How should the test be changed?
1. Change "def to_ary; end;" to "def to_ary; []; end" My guess will be option 1 since this is for testing the array comparison utilizing to_ary method. Attached 2nd patch file for changing the test case in test_array.rb as discussed and decided by Charles.
Fixed in commit 5058 on trunk and 5059 on 1.0 branch (patch by Hung Huynh, test patch by Wirianto Djunaidi)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||