ruby-changes:56274
From: Nobuyoshi <ko1@a...>
Date: Sat, 29 Jun 2019 18:50:19 +0900 (JST)
Subject: [ruby-changes:56274] Nobuyoshi Nakada: 27723b699b (trunk): Should not warn massign parameters as unused
https://git.ruby-lang.org/ruby.git/commit/?id=27723b699b From 27723b699b5fbad49a7bb16936d5a7d8e80376ba Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 29 Jun 2019 18:45:24 +0900 Subject: Should not warn massign parameters as unused diff --git a/parse.y b/parse.y index 38eab9c..7f7a4d0 100644 --- a/parse.y +++ b/parse.y @@ -404,6 +404,7 @@ static NODE *literal_concat(struct parser_params*,NODE*,NODE*,const YYLTYPE*); https://github.com/ruby/ruby/blob/trunk/parse.y#L404 static NODE *new_evstr(struct parser_params*,NODE*,const YYLTYPE*); static NODE *evstr2dstr(struct parser_params*,NODE*); static NODE *splat_array(NODE*); +static void mark_lvar_used(struct parser_params *p, NODE *rhs); static NODE *call_bin_op(struct parser_params*,NODE*,ID,NODE*,const YYLTYPE*,const YYLTYPE*); static NODE *call_uni_op(struct parser_params*,NODE*,ID,const YYLTYPE*,const YYLTYPE*); @@ -3150,6 +3151,7 @@ f_marg : f_norm_arg https://github.com/ruby/ruby/blob/trunk/parse.y#L3151 { /*%%%*/ $$ = assignable(p, $1, 0, &@$); + mark_lvar_used(p, $$); /*% %*/ /*% ripper: assignable(p, $1) %*/ } diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index ff62aef..b63f170 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -961,10 +961,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L961 assert_warning(/assigned but unused variable/) {o.instance_eval("def foo; a=1; nil; end")} assert_warning(/assigned but unused variable/) {o.instance_eval("def bar; a=1; a(); end")} a = "\u{3042}" - 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")} + assert_warning(/#{a}/) {o.instance_eval("def foo0; #{a}=1; nil; end")} + assert_warning(/assigned but unused variable/) {o.instance_eval("def foo1; tap {a=1; a()}; end")} + assert_warning('') {o.instance_eval("def bar1; a=a=1; nil; end")} + assert_warning(/assigned but unused variable/) {o.instance_eval("def bar2; a, = 1, 2; end")} + assert_warning('') {o.instance_eval("def marg1(a); nil; end")} + assert_warning('') {o.instance_eval("def marg2((a)); nil; end")} end def test_named_capture_conflict -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/