Project

General

Profile

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

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

View differences:

hash.c
1553 1553
		VALUE key, val = Qnil;
1554 1554

  
1555 1555
		if (NIL_P(v)) {
1556
#if 0 /* refix in the next release */
1557 1556
		    rb_raise(rb_eArgError, "wrong element type %s at %ld (expected array)",
1558 1557
			     rb_builtin_class_name(e), i);
1559

  
1560
#else
1561
		    rb_warn("wrong element type %s at %ld (expected array)",
1562
			    rb_builtin_class_name(e), i);
1563
		    rb_warn("ignoring wrong elements is deprecated, remove them explicitly");
1564
		    rb_warn("this causes ArgumentError in the next release");
1565
		    continue;
1566
#endif
1567 1558
		}
1568 1559
		switch (RARRAY_LEN(v)) {
1569 1560
		  default:
spec/ruby/core/hash/constructor_spec.rb
45 45
  it "ignores elements that are not arrays" do
46 46
    -> {
47 47
      Hash[[:a]].should == {}
48
    }.should complain(/ignoring wrong elements/)
48
    }.should raise_error(ArgumentError)
49 49
    -> {
50 50
      Hash[[:nil]].should == {}
51
    }.should complain(/ignoring wrong elements/)
51
    }.should raise_error(ArgumentError)
52 52
  end
53 53

  
54 54
  it "raises an ArgumentError for arrays of more than 2 elements" do
test/ruby/test_hash.rb
149 149
    assert_equal(nil, h['b'])
150 150
    assert_equal(300, h['c'])
151 151

  
152
    h = @cls[[["a", 100], "b", ["c", 300]]]
153
    assert_equal(100, h['a'])
154
    assert_equal(nil, h['b'])
155
    assert_equal(300, h['c'])
152
    assert_raise(ArgumentError) do
153
      @cls[[["a", 100], "b", ["c", 300]]]
154
    end
156 155
  end
157 156

  
158 157
  def test_s_AREF_duplicated_key
......
944 943

  
945 944
  def test_create
946 945
    assert_equal({1=>2, 3=>4}, @cls[[[1,2],[3,4]]])
947
    assert_raise(ArgumentError) { Hash[0, 1, 2] }
948
    assert_warning(/wrong element type Integer at 1 /) {@cls[[[1, 2], 3]]}
946
    assert_raise(ArgumentError) { @cls[0, 1, 2] }
947
    assert_raise(ArgumentError) { @cls[[[0, 1], 2]] }
949 948
    bug5406 = '[ruby-core:39945]'
950 949
    assert_raise(ArgumentError, bug5406) { @cls[[[1, 2], [3, 4, 5]]] }
951 950
    assert_equal({1=>2, 3=>4}, @cls[1,2,3,4])