mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Revert "range.c: prohibit (1..nil)
"
This reverts commit a44c010764a16ae09aaed49d76eec055ca0057c8. Refs #14845. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4f4ed3e9ea
commit
606d6b3470
4 changed files with 41 additions and 35 deletions
|
@ -7188,10 +7188,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
|
|||
case NODE_DOT2:
|
||||
case NODE_DOT3:{
|
||||
int excl = type == NODE_DOT3;
|
||||
VALUE flag = INT2FIX(excl);
|
||||
const NODE *b = node->nd_beg;
|
||||
const NODE *e = node->nd_end;
|
||||
VALUE flag = INT2FIX(excl | (e ? 0 : 2));
|
||||
if (number_literal_p(b) && e && number_literal_p(e)) {
|
||||
if (number_literal_p(b) && number_literal_p(e)) {
|
||||
if (!popped) {
|
||||
VALUE val = rb_range_new(b->nd_lit, e->nd_lit, excl);
|
||||
iseq_add_mark_object_compile_time(iseq, val);
|
||||
|
|
12
parse.y
12
parse.y
|
@ -1916,16 +1916,24 @@ arg : lhs '=' arg_rhs
|
|||
| arg tDOT2
|
||||
{
|
||||
/*%%%*/
|
||||
YYLTYPE loc;
|
||||
loc.beg_pos = @2.end_pos;
|
||||
loc.end_pos = @2.end_pos;
|
||||
|
||||
value_expr($1);
|
||||
$$ = NEW_DOT2($1, 0, &@$);
|
||||
$$ = NEW_DOT2($1, new_nil(&loc), &@$);
|
||||
/*% %*/
|
||||
/*% ripper: dot2!($1, Qnil) %*/
|
||||
}
|
||||
| arg tDOT3
|
||||
{
|
||||
/*%%%*/
|
||||
YYLTYPE loc;
|
||||
loc.beg_pos = @2.end_pos;
|
||||
loc.end_pos = @2.end_pos;
|
||||
|
||||
value_expr($1);
|
||||
$$ = NEW_DOT3($1, 0, &@$);
|
||||
$$ = NEW_DOT3($1, new_nil(&loc), &@$);
|
||||
/*% %*/
|
||||
/*% ripper: dot3!($1, Qnil) %*/
|
||||
}
|
||||
|
|
14
range.c
14
range.c
|
@ -37,7 +37,7 @@ static VALUE r_cover_p(VALUE, VALUE, VALUE, VALUE);
|
|||
static void
|
||||
range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
|
||||
{
|
||||
if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && end != Qundef) {
|
||||
if ((!FIXNUM_P(beg) || !FIXNUM_P(end)) && !NIL_P(end)) {
|
||||
VALUE v;
|
||||
|
||||
v = rb_funcall(beg, id_cmp, 1, end);
|
||||
|
@ -47,16 +47,15 @@ range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
|
|||
|
||||
RANGE_SET_EXCL(range, exclude_end);
|
||||
RANGE_SET_BEG(range, beg);
|
||||
RANGE_SET_END(range, end == Qundef ? Qnil : end);
|
||||
RANGE_SET_END(range, end);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_range_new(VALUE beg, VALUE end, int flag)
|
||||
rb_range_new(VALUE beg, VALUE end, int exclude_end)
|
||||
{
|
||||
VALUE range = rb_obj_alloc(rb_cRange);
|
||||
|
||||
if (flag & 2) end = Qundef;
|
||||
range_init(range, beg, end, RBOOL(flag & 1));
|
||||
range_init(range, beg, end, RBOOL(exclude_end));
|
||||
return range;
|
||||
}
|
||||
|
||||
|
@ -86,7 +85,6 @@ range_initialize(int argc, VALUE *argv, VALUE range)
|
|||
|
||||
rb_scan_args(argc, argv, "21", &beg, &end, &flags);
|
||||
range_modify(range);
|
||||
if (NIL_P(end)) end = Qundef;
|
||||
range_init(range, beg, end, RBOOL(RTEST(flags)));
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -1341,7 +1339,7 @@ range_dumper(VALUE range)
|
|||
|
||||
rb_ivar_set(v, id_excl, RANGE_EXCL(range));
|
||||
rb_ivar_set(v, id_beg, RANGE_BEG(range));
|
||||
if (!NIL_P(RANGE_END(range))) rb_ivar_set(v, id_end, RANGE_END(range));
|
||||
rb_ivar_set(v, id_end, RANGE_END(range));
|
||||
return v;
|
||||
}
|
||||
|
||||
|
@ -1356,7 +1354,7 @@ range_loader(VALUE range, VALUE obj)
|
|||
|
||||
range_modify(range);
|
||||
beg = rb_ivar_get(obj, id_beg);
|
||||
end = rb_ivar_lookup(obj, id_end, Qundef);
|
||||
end = rb_ivar_get(obj, id_end);
|
||||
excl = rb_ivar_get(obj, id_excl);
|
||||
if (!NIL_P(excl)) {
|
||||
range_init(range, beg, end, RBOOL(RTEST(excl)));
|
||||
|
|
|
@ -13,8 +13,8 @@ class TestRange < Test::Unit::TestCase
|
|||
|
||||
assert_raise(ArgumentError) { (1.."3") }
|
||||
|
||||
assert_equal((0..), Range.new(0, nil, false))
|
||||
assert_equal((0...), Range.new(0, nil, true))
|
||||
assert_equal((0..nil), Range.new(0, nil, false))
|
||||
assert_equal((0...nil), Range.new(0, nil, true))
|
||||
|
||||
obj = Object.new
|
||||
def obj.<=>(other)
|
||||
|
@ -161,15 +161,15 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_not_equal(r, (1..2))
|
||||
assert_not_equal(r, (0..2))
|
||||
assert_not_equal(r, (0...1))
|
||||
assert_not_equal(r, (0..))
|
||||
assert_not_equal(r, (0..nil))
|
||||
subclass = Class.new(Range)
|
||||
assert_equal(r, subclass.new(0,1))
|
||||
|
||||
r = (0..)
|
||||
r = (0..nil)
|
||||
assert_equal(r, r)
|
||||
assert_equal(r, (0..))
|
||||
assert_equal(r, (0..nil))
|
||||
assert_not_equal(r, 0)
|
||||
assert_not_equal(r, (0...))
|
||||
assert_not_equal(r, (0...nil))
|
||||
subclass = Class.new(Range)
|
||||
assert_equal(r, subclass.new(0,nil))
|
||||
end
|
||||
|
@ -185,11 +185,11 @@ class TestRange < Test::Unit::TestCase
|
|||
subclass = Class.new(Range)
|
||||
assert_operator(r, :eql?, subclass.new(0,1))
|
||||
|
||||
r = (0..)
|
||||
r = (0..nil)
|
||||
assert_operator(r, :eql?, r)
|
||||
assert_operator(r, :eql?, 0..)
|
||||
assert_operator(r, :eql?, 0..nil)
|
||||
assert_not_operator(r, :eql?, 0)
|
||||
assert_not_operator(r, :eql?, 0...)
|
||||
assert_not_operator(r, :eql?, 0...nil)
|
||||
subclass = Class.new(Range)
|
||||
assert_operator(r, :eql?, subclass.new(0,nil))
|
||||
end
|
||||
|
@ -198,8 +198,8 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_kind_of(Integer, (0..1).hash)
|
||||
assert_equal((0..1).hash, (0..1).hash)
|
||||
assert_not_equal((0..1).hash, (0...1).hash)
|
||||
assert_equal((0..).hash, (0..).hash)
|
||||
assert_not_equal((0..).hash, (0...).hash)
|
||||
assert_equal((0..nil).hash, (0..nil).hash)
|
||||
assert_not_equal((0..nil).hash, (0...nil).hash)
|
||||
end
|
||||
|
||||
def test_step
|
||||
|
@ -380,9 +380,9 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_equal(0, (0..1).begin)
|
||||
assert_equal(1, (0..1).end)
|
||||
assert_equal(1, (0...1).end)
|
||||
assert_equal(0, (0..).begin)
|
||||
assert_equal(nil, (0..).end)
|
||||
assert_equal(nil, (0...).end)
|
||||
assert_equal(0, (0..nil).begin)
|
||||
assert_equal(nil, (0..nil).end)
|
||||
assert_equal(nil, (0...nil).end)
|
||||
end
|
||||
|
||||
def test_first_last
|
||||
|
@ -402,17 +402,17 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_equal("c", ("a"..."c").last)
|
||||
assert_equal(0, (2...0).last)
|
||||
|
||||
assert_equal([0, 1, 2], (0..).first(3))
|
||||
assert_equal(0, (0..).first)
|
||||
assert_equal("a", ("a"..).first)
|
||||
assert_equal([0, 1, 2], (0..nil).first(3))
|
||||
assert_equal(0, (0..nil).first)
|
||||
assert_equal("a", ("a"..nil).first)
|
||||
# XXX: How should (0...).last(3) behave?
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal("0..1", (0..1).to_s)
|
||||
assert_equal("0...1", (0...1).to_s)
|
||||
assert_equal("0..", (0..).to_s)
|
||||
assert_equal("0...", (0...).to_s)
|
||||
assert_equal("0..", (0..nil).to_s)
|
||||
assert_equal("0...", (0...nil).to_s)
|
||||
|
||||
bug11767 = '[ruby-core:71811] [Bug #11767]'
|
||||
assert_predicate(("0".taint.."1").to_s, :tainted?, bug11767)
|
||||
|
@ -423,8 +423,8 @@ class TestRange < Test::Unit::TestCase
|
|||
def test_inspect
|
||||
assert_equal("0..1", (0..1).inspect)
|
||||
assert_equal("0...1", (0...1).inspect)
|
||||
assert_equal("0..", (0..).inspect)
|
||||
assert_equal("0...", (0...).inspect)
|
||||
assert_equal("0..", (0..nil).inspect)
|
||||
assert_equal("0...", (0...nil).inspect)
|
||||
|
||||
bug11767 = '[ruby-core:71811] [Bug #11767]'
|
||||
assert_predicate(("0".taint.."1").inspect, :tainted?, bug11767)
|
||||
|
@ -435,8 +435,8 @@ class TestRange < Test::Unit::TestCase
|
|||
def test_eqq
|
||||
assert_operator(0..10, :===, 5)
|
||||
assert_not_operator(0..10, :===, 11)
|
||||
assert_operator(5.., :===, 11)
|
||||
assert_not_operator(5.., :===, 0)
|
||||
assert_operator(5..nil, :===, 11)
|
||||
assert_not_operator(5..nil, :===, 0)
|
||||
end
|
||||
|
||||
def test_eqq_time
|
||||
|
|
Loading…
Add table
Reference in a new issue