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

parse.y: refine negate_lit_gen error message

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-01-17 06:05:37 +00:00
parent 377b189562
commit edb8b498f9

27
parse.y
View file

@ -9985,11 +9985,18 @@ new_yield(struct parser_params *p, NODE *node, const YYLTYPE *loc)
static VALUE
negate_lit(struct parser_params *p, VALUE lit)
{
int type = TYPE(lit);
switch (type) {
case T_FIXNUM:
lit = LONG2FIX(-FIX2LONG(lit));
break;
if (FIXNUM_P(lit)) {
return LONG2FIX(-FIX2LONG(lit));
}
if (SPECIAL_CONST_P(lit)) {
#if USE_FLONUM
if (FLONUM_P(lit)) {
return DBL2NUM(-RFLOAT_VALUE(lit));
}
#endif
goto unknown;
}
switch (BUILTIN_TYPE(lit)) {
case T_BIGNUM:
BIGNUM_NEGATE(lit);
lit = rb_big_norm(lit);
@ -10002,16 +10009,12 @@ negate_lit(struct parser_params *p, VALUE lit)
RCOMPLEX_SET_IMAG(lit, negate_lit(p, RCOMPLEX(lit)->imag));
break;
case T_FLOAT:
#if USE_FLONUM
if (FLONUM_P(lit)) {
lit = DBL2NUM(-RFLOAT_VALUE(lit));
break;
}
#endif
RFLOAT(lit)->float_value = -RFLOAT_VALUE(lit);
break;
unknown:
default:
rb_parser_fatal(p, "unknown literal type (%d) passed to negate_lit", type);
rb_parser_fatal(p, "unknown literal type (%s) passed to negate_lit",
rb_builtin_class_name(lit));
break;
}
return lit;