summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-04 09:31:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-04 09:31:02 +0000
commit72dfee9a96069791b888d1596a48ddd07caf5c51 (patch)
tree7c120730347c98ec84af6f5cfdde481be9ee23ae /array.c
parentf9833b7d5f4cc54193049043e04bf4fcf27b13e6 (diff)
* 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
Diffstat (limited to 'array.c')
-rw-r--r--array.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/array.c b/array.c
index 666a68a..759c4a3 100644
--- a/array.c
+++ b/array.c
@@ -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]);