ruby-changes:54269
From: mrkn <ko1@a...>
Date: Fri, 21 Dec 2018 22:05:22 +0900 (JST)
Subject: [ruby-changes:54269] mrkn:r66478 (trunk): range.c: reject ArithmeticSequence in rb_range_values
mrkn 2018-12-21 22:05:16 +0900 (Fri, 21 Dec 2018) New Revision: 66478 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66478 Log: range.c: reject ArithmeticSequence in rb_range_values Reject ArithmeticSequence in rb_range_values so that methods like Array#[] raises TypeError for ArithmeticSequence as an index. Modified files: trunk/enumerator.c trunk/internal.h trunk/range.c trunk/test/ruby/test_array.rb Index: internal.h =================================================================== --- internal.h (revision 66477) +++ internal.h (revision 66478) @@ -1414,6 +1414,7 @@ void rb_encdb_set_unicode(int index); https://github.com/ruby/ruby/blob/trunk/internal.h#L1414 PUREFUNC(int rb_data_is_encoding(VALUE obj)); /* enum.c */ +extern VALUE rb_cArithSeq; VALUE rb_f_send(int argc, VALUE *argv, VALUE recv); VALUE rb_nmin_run(VALUE obj, VALUE num, int by, int rev, int ary); Index: range.c =================================================================== --- range.c (revision 66477) +++ range.c (revision 66478) @@ -1141,6 +1141,9 @@ rb_range_values(VALUE range, VALUE *begp https://github.com/ruby/ruby/blob/trunk/range.c#L1141 e = RANGE_END(range); excl = EXCL(range); } + else if (RTEST(rb_obj_is_kind_of(range, rb_cArithSeq))) { + return (int)Qfalse; + } else { VALUE x; b = rb_check_funcall(range, id_beg, 0, 0); Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 66477) +++ test/ruby/test_array.rb (revision 66478) @@ -2244,6 +2244,7 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L2244 def test_aref assert_raise(ArgumentError) { [][0, 0, 0] } + assert_raise(TypeError) { [][(1..10).step(2)] } end def test_fetch Index: enumerator.c =================================================================== --- enumerator.c (revision 66477) +++ enumerator.c (revision 66478) @@ -169,7 +169,7 @@ struct enum_chain { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L169 long pos; }; -static VALUE rb_cArithSeq; +VALUE rb_cArithSeq; /* * Enumerator -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/