@@ -232,17 +232,19 @@ coerce_body(VALUE *x)
232232 return rb_funcall (x [1 ], id_coerce , 1 , x [0 ]);
233233}
234234
235+ NORETURN (static void coerce_failed (VALUE x , VALUE y ));
236+ static void
237+ coerce_failed (VALUE x , VALUE y )
238+ {
239+ rb_raise (rb_eTypeError , "%" PRIsVALUE " can't be coerced into %" PRIsVALUE ,
240+ (rb_special_const_p (y )? rb_inspect (y ) : rb_obj_class (y )),
241+ rb_obj_class (x ));
242+ }
243+
235244static VALUE
236245coerce_rescue (VALUE * x )
237246{
238- volatile VALUE v = rb_inspect (x [1 ]);
239-
240- rb_raise (rb_eTypeError , "%s can't be coerced into %s" ,
241- rb_special_const_p (x [1 ])?
242- RSTRING_PTR (v ):
243- rb_obj_classname (x [1 ]),
244- rb_obj_classname (x [0 ]));
245-
247+ coerce_failed (x [0 ], x [1 ]);
246248 return Qnil ; /* dummy */
247249}
248250
@@ -3297,11 +3299,7 @@ bit_coerce(VALUE *x, VALUE *y, int err)
32973299 if (!FIXNUM_P (* x ) && !RB_TYPE_P (* x , T_BIGNUM )
32983300 && !FIXNUM_P (* y ) && !RB_TYPE_P (* y , T_BIGNUM )) {
32993301 if (!err ) return FALSE;
3300- rb_raise (rb_eTypeError ,
3301- "%s can't be coerced into %s for bitwise arithmetic" ,
3302- rb_special_const_p (* y ) ?
3303- RSTRING_PTR (rb_inspect (* y )) : rb_obj_classname (* y ),
3304- rb_obj_classname (* x ));
3302+ coerce_failed (* x , * y );
33053303 }
33063304 }
33073305 return TRUE;
0 commit comments