Project

General

Profile

Bug #7300 » remove-hash-constructor-compatibility.patch

mame (Yusuke Endoh), 12/26/2018 08:06 AM

View differences:

hash.c
VALUE key, val = Qnil;
if (NIL_P(v)) {
#if 0 /* refix in the next release */
rb_raise(rb_eArgError, "wrong element type %s at %ld (expected array)",
rb_builtin_class_name(e), i);
#else
rb_warn("wrong element type %s at %ld (expected array)",
rb_builtin_class_name(e), i);
rb_warn("ignoring wrong elements is deprecated, remove them explicitly");
rb_warn("this causes ArgumentError in the next release");
continue;
#endif
}
switch (RARRAY_LEN(v)) {
default:
spec/ruby/core/hash/constructor_spec.rb
it "ignores elements that are not arrays" do
-> {
Hash[[:a]].should == {}
}.should complain(/ignoring wrong elements/)
}.should raise_error(ArgumentError)
-> {
Hash[[:nil]].should == {}
}.should complain(/ignoring wrong elements/)
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError for arrays of more than 2 elements" do
test/ruby/test_hash.rb
assert_equal(nil, h['b'])
assert_equal(300, h['c'])
h = @cls[[["a", 100], "b", ["c", 300]]]
assert_equal(100, h['a'])
assert_equal(nil, h['b'])
assert_equal(300, h['c'])
assert_raise(ArgumentError) do
@cls[[["a", 100], "b", ["c", 300]]]
end
end
def test_s_AREF_duplicated_key
......
def test_create
assert_equal({1=>2, 3=>4}, @cls[[[1,2],[3,4]]])
assert_raise(ArgumentError) { Hash[0, 1, 2] }
assert_warning(/wrong element type Integer at 1 /) {@cls[[[1, 2], 3]]}
assert_raise(ArgumentError) { @cls[0, 1, 2] }
assert_raise(ArgumentError) { @cls[[[0, 1], 2]] }
bug5406 = '[ruby-core:39945]'
assert_raise(ArgumentError, bug5406) { @cls[[[1, 2], [3, 4, 5]]] }
assert_equal({1=>2, 3=>4}, @cls[1,2,3,4])
    (1-1/1)