From af9b0da125871c6bfbc3b7893d199a79420e5833 Mon Sep 17 00:00:00 2001 From: mame Date: Sat, 4 Nov 2017 14:24:16 +0000 Subject: Avoid usage of the magic number `(NODE*)-1` This magic number has two meanings depending upon the context: * "required keyword argument (no name)" on NODE_LASGN (`def foo(x:)`) * "rest argument (no name)" on NODE_MASGN and NODE_POSTARG ('a, b, * = ary` or `a, b, *, z = ary`) To show this intention explicitly, two macros are introduced: NODE_SPECIAL_REQUIRED_KEYWORD and NODE_SPECIAL_NO_NAME_REST. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 4bcbd0cec8..76bc107abe 100644 --- a/compile.c +++ b/compile.c @@ -3708,7 +3708,7 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, const NODE *rhsn = node->nd_value; const NODE *splatn = node->nd_args; const NODE *lhsn = node->nd_head; - int lhs_splat = (splatn && (VALUE)splatn != (VALUE)-1) ? 1 : 0; + int lhs_splat = (splatn && splatn != NODE_SPECIAL_NO_NAME_REST) ? 1 : 0; if (!popped || splatn || !compile_massign_opt(iseq, ret, rhsn, lhsn)) { int llen = 0; @@ -3765,12 +3765,12 @@ compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, const NODE *postn = splatn->nd_2nd; const NODE *restn = splatn->nd_1st; int num = (int)postn->nd_alen; - int flag = 0x02 | (((VALUE)restn == (VALUE)-1) ? 0x00 : 0x01); + int flag = 0x02 | ((restn == NODE_SPECIAL_NO_NAME_REST) ? 0x00 : 0x01); ADD_INSN2(ret, nd_line(splatn), expandarray, INT2FIX(num), INT2FIX(flag)); - if ((VALUE)restn != (VALUE)-1) { + if (restn != NODE_SPECIAL_NO_NAME_REST) { CHECK(compile_massign_lhs(iseq, ret, restn)); } while (postn) { -- cgit v1.2.3