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

* array.c (rb_ary_aref): give warning if index is a symbol.

[ruby-list:37217]

* array.c (rb_ary_aset): raise TypeError if index is a symbol.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-03-04 09:31:02 +00:00
parent f9833b7d5f
commit 72dfee9a96
3 changed files with 25 additions and 0 deletions

View file

@ -1,3 +1,10 @@
Tue Mar 4 17:54:30 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c (rb_ary_aref): give warning if index is a symbol.
[ruby-list:37217]
* array.c (rb_ary_aset): raise TypeError if index is a symbol.
Tue Nov 13 14:39:11 2001 WATANABE Tetsuya <tetsu@jpn.hp.com>
* missing/strftime.c: HP-UX support.

15
array.c
View file

@ -500,6 +500,9 @@ rb_ary_aref(argc, argv, ary)
long beg, len;
if (argc == 2) {
if (SYMBOL_P(argv[0])) {
rb_raise(rb_eTypeError, "Symbol as array index");
}
beg = NUM2LONG(argv[0]);
len = NUM2LONG(argv[1]);
if (beg < 0) {
@ -515,6 +518,9 @@ rb_ary_aref(argc, argv, ary)
if (FIXNUM_P(arg)) {
return rb_ary_entry(ary, FIX2LONG(arg));
}
if (SYMBOL_P(arg)) {
rb_raise(rb_eTypeError, "Symbol as array index");
}
/* check if idx is Range */
switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
case Qfalse:
@ -714,6 +720,12 @@ rb_ary_aset(argc, argv, ary)
long offset, beg, len;
if (argc == 3) {
if (SYMBOL_P(argv[0])) {
rb_raise(rb_eTypeError, "Symbol as array index");
}
if (SYMBOL_P(argv[1])) {
rb_raise(rb_eTypeError, "Symbol as subarray length");
}
rb_ary_update(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
return argv[2];
}
@ -724,6 +736,9 @@ rb_ary_aset(argc, argv, ary)
offset = FIX2LONG(argv[0]);
goto fixnum;
}
if (SYMBOL_P(argv[0])) {
rb_raise(rb_eTypeError, "Symbol as array index");
}
if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */
rb_ary_update(ary, beg, len, argv[1]);

View file

@ -943,6 +943,9 @@ rb_num2long(val)
case T_BIGNUM:
return rb_big2long(val);
case T_SYMBOL:
rb_warning("treating Symbol as an integer");
/* fall through */
default:
val = rb_to_int(val);
return NUM2LONG(val);