1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

range.c: Fix an exception message in rb_range_beg_len

[Bug #17271]
This commit is contained in:
Kenta Murata 2020-10-20 16:00:35 +09:00
parent ade411465d
commit 18cecda46e
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062
2 changed files with 5 additions and 5 deletions

View file

@ -1332,7 +1332,7 @@ rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
VALUE
rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
{
long beg, end, origbeg, origend;
long beg, end;
VALUE b, e;
int excl;
@ -1341,8 +1341,6 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
beg = NIL_P(b) ? 0 : NUM2LONG(b);
end = NIL_P(e) ? -1 : NUM2LONG(e);
if (NIL_P(e)) excl = 0;
origbeg = beg;
origend = end;
if (beg < 0) {
beg += len;
if (beg < 0)
@ -1368,8 +1366,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
out_of_range:
if (err) {
rb_raise(rb_eRangeError, "%ld..%s%ld out of range",
origbeg, excl ? "." : "", origend);
rb_raise(rb_eRangeError, "%+"PRIsVALUE" out of range", range);
}
return Qnil;
}

View file

@ -2381,6 +2381,9 @@ class TestArray < Test::Unit::TestCase
assert_raise(ArgumentError) { [0].freeze[0, 0, 0] = 0 }
assert_raise(TypeError) { [0][:foo] = 0 }
assert_raise(FrozenError) { [0].freeze[:foo] = 0 }
# [Bug #17271]
assert_raise_with_message(RangeError, "-7.. out of range") { [*0..5][-7..] = 1 }
end
def test_first2