Skip to content

Commit

Permalink
Ranges should not rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Nov 17, 2016
1 parent 1685eff commit 176d93d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/range.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ mrb_range_initialize(mrb_state *mrb, mrb_value range)
exclusive = FALSE; exclusive = FALSE;
} }
/* Ranges are immutable, so that they should be initialized only once. */ /* Ranges are immutable, so that they should be initialized only once. */
if (mrb_range_ptr(range)->edges) {
mrb_name_error(mrb, mrb_intern_lit(mrb, "initialize"), "`initialize' called twice");
}
range_init(mrb, range, beg, end, exclusive); range_init(mrb, range, beg, end, exclusive);
return range; return range;
} }
Expand Down
2 changes: 2 additions & 0 deletions test/t/range.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
assert_true a.exclude_end? assert_true a.exclude_end?
assert_equal (1..10), b assert_equal (1..10), b
assert_false b.exclude_end? assert_false b.exclude_end?

assert_raise(NameError) { (0..1).send(:initialize, 1, 3) }
end end


assert('Range#last', '15.2.14.4.10') do assert('Range#last', '15.2.14.4.10') do
Expand Down

0 comments on commit 176d93d

Please sign in to comment.