ruby-changes:49764
From: nobu <ko1@a...>
Date: Wed, 17 Jan 2018 15:05:42 +0900 (JST)
Subject: [ruby-changes:49764] nobu:r61882 (trunk): parse.y: refine negate_lit_gen error message
nobu 2018-01-17 15:05:37 +0900 (Wed, 17 Jan 2018) New Revision: 61882 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61882 Log: parse.y: refine negate_lit_gen error message Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61881) +++ parse.y (revision 61882) @@ -9985,11 +9985,18 @@ new_yield(struct parser_params *p, NODE https://github.com/ruby/ruby/blob/trunk/parse.y#L9985 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, VALU https://github.com/ruby/ruby/blob/trunk/parse.y#L10009 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; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/