ruby-changes:48224
From: nobu <ko1@a...>
Date: Sun, 22 Oct 2017 10:37:42 +0900 (JST)
Subject: [ruby-changes:48224] nobu:r60339 (trunk): parse.y: workaround for warnings
nobu 2017-10-22 10:37:36 +0900 (Sun, 22 Oct 2017) New Revision: 60339 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60339 Log: parse.y: workaround for warnings * parse.y (mark_lvar_used): enable workaround to suppress unused local variables. [ruby-core:82656] [Bug #13872] Modified files: trunk/parse.y trunk/test/ruby/test_parse.rb Index: parse.y =================================================================== --- parse.y (revision 60338) +++ parse.y (revision 60339) @@ -9927,6 +9927,33 @@ splat_array(NODE* node) https://github.com/ruby/ruby/blob/trunk/parse.y#L9927 return 0; } +static void +mark_lvar_used(struct parser_params *parser, NODE *rhs) +{ + ID *vidp = NULL; + if (!rhs) return; + switch (nd_type(rhs)) { + case NODE_LASGN: + if (local_id_ref(rhs->nd_vid, vidp)) { + if (vidp) *vidp |= LVAR_USED; + } + break; + case NODE_DASGN: + case NODE_DASGN_CURR: + if (dvar_defined_ref(rhs->nd_vid, vidp)) { + if (vidp) *vidp |= LVAR_USED; + } + break; +#if 0 + case NODE_MASGN: + for (rhs = rhs->nd_head; rhs; rhs = rhs->nd_next) { + mark_lvar_used(parser, rhs->nd_head); + } + break; +#endif + } +} + static NODE * node_assign_gen(struct parser_params *parser, NODE *lhs, NODE *rhs, int column) { @@ -10007,6 +10034,13 @@ value_expr_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L10034 node = node->nd_2nd; break; + case NODE_LASGN: + case NODE_DASGN: + case NODE_DASGN_CURR: + case NODE_MASGN: + mark_lvar_used(parser, node); + return TRUE; + default: return TRUE; } Index: test/ruby/test_parse.rb =================================================================== --- test/ruby/test_parse.rb (revision 60338) +++ test/ruby/test_parse.rb (revision 60339) @@ -890,6 +890,7 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L890 assert_warning(/#{a}/) {o.instance_eval("def foo; #{a}=1; nil; end")} o = Object.new assert_warning(/assigned but unused variable/) {o.instance_eval("def foo; tap {a=1; a()}; end")} + assert_warning('') {o.instance_eval("def bar; a=a=1; nil; end")} end def test_named_capture_conflict -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/