diff --git a/array.c b/array.c index 5cb86f2532..a2438a3206 100644 --- a/array.c +++ b/array.c @@ -655,6 +655,12 @@ rb_check_array_type(VALUE ary) return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_ary); } +VALUE +rb_check_to_array(VALUE ary) +{ + return rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a); +} + /* * call-seq: * Array.try_convert(obj) -> array or nil diff --git a/internal.h b/internal.h index 4715638d5c..59f5d640cc 100644 --- a/internal.h +++ b/internal.h @@ -1059,6 +1059,7 @@ VALUE rb_ary_aref1(VALUE ary, VALUE i); VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e); size_t rb_ary_memsize(VALUE); VALUE rb_to_array_type(VALUE obj); +VALUE rb_check_to_array(VALUE ary); #if defined(__GNUC__) && defined(HAVE_VA_ARGS_MACRO) #define rb_ary_new_from_args(n, ...) \ __extension__ ({ \ diff --git a/object.c b/object.c index 48c97b6f36..05502833e5 100644 --- a/object.c +++ b/object.c @@ -3595,7 +3595,7 @@ rb_Array(VALUE val) VALUE tmp = rb_check_array_type(val); if (NIL_P(tmp)) { - tmp = rb_check_convert_type_with_id(val, T_ARRAY, "Array", idTo_a); + tmp = rb_check_to_array(val); if (NIL_P(tmp)) { return rb_ary_new3(1, val); } diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 0fbf39d275..1ba3cceb8b 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2968,8 +2968,8 @@ static VALUE vm_concat_array(VALUE ary1, VALUE ary2st) { const VALUE ary2 = ary2st; - VALUE tmp1 = rb_check_convert_type_with_id(ary1, T_ARRAY, "Array", idTo_a); - VALUE tmp2 = rb_check_convert_type_with_id(ary2, T_ARRAY, "Array", idTo_a); + VALUE tmp1 = rb_check_to_array(ary1); + VALUE tmp2 = rb_check_to_array(ary2); if (NIL_P(tmp1)) { tmp1 = rb_ary_new3(1, ary1); @@ -2988,7 +2988,7 @@ vm_concat_array(VALUE ary1, VALUE ary2st) static VALUE vm_splat_array(VALUE flag, VALUE ary) { - VALUE tmp = rb_check_convert_type_with_id(ary, T_ARRAY, "Array", idTo_a); + VALUE tmp = rb_check_to_array(ary); if (NIL_P(tmp)) { return rb_ary_new3(1, ary); }