[前][次][番号順一覧][スレッド一覧]

ruby-changes:59340

From: Nobuyoshi <ko1@a...>
Date: Fri, 20 Dec 2019 14:38:51 +0900 (JST)
Subject: [ruby-changes:59340] a8bddb3a18 (master): Refined the warning message for numbered-parameter like variables

https://git.ruby-lang.org/ruby.git/commit/?id=a8bddb3a18

From a8bddb3a189545a2bef8ee7cffdb328d8de7974c Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 20 Dec 2019 14:29:42 +0900
Subject: Refined the warning message for numbered-parameter like variables

[Bug #16438]

diff --git a/parse.y b/parse.y
index 7247afa..05e2c1d 100644
--- a/parse.y
+++ b/parse.y
@@ -11836,7 +11836,7 @@ static void https://github.com/ruby/ruby/blob/trunk/parse.y#L11836
 numparam_name(struct parser_params *p, ID id)
 {
     if (!NUMPARAM_ID_P(id)) return;
-    rb_warn1("`_%d' is used as numbered parameter",
+    rb_warn1("`_%d' is reserved as numbered parameter",
 	     WARN_I(NUMPARAM_ID_TO_IDX(id)));
 }
 
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 5eb69c5..540ab7b 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1437,12 +1437,13 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1437
     assert_syntax_error('-> {_1; -> {_2}}', /numbered parameter is already used/)
     assert_syntax_error('-> {-> {_1}; _2}', /numbered parameter is already used/)
     assert_syntax_error('proc {_1; _1 = nil}', /Can't assign to numbered parameter _1/)
-    assert_warn(/`_1' is used as numbered parameter/) {eval('proc {_1 = nil}')}
-    assert_warn(/`_2' is used as numbered parameter/) {eval('_2=1')}
-    assert_warn(/`_3' is used as numbered parameter/) {eval('proc {|_3|}')}
-    assert_warn(/`_4' is used as numbered parameter/) {instance_eval('def x(_4) end')}
-    assert_warn(/`_5' is used as numbered parameter/) {instance_eval('def _5; end')}
-    assert_warn(/`_6' is used as numbered parameter/) {instance_eval('def self._6; end')}
+    mesg = proc {|n| /`_#{n}' is reserved as numbered parameter/}
+    assert_warn(mesg[1]) {eval('proc {_1 = nil}')}
+    assert_warn(mesg[2]) {eval('_2=1')}
+    assert_warn(mesg[3]) {eval('proc {|_3|}')}
+    assert_warn(mesg[4]) {instance_eval('def x(_4) end')}
+    assert_warn(mesg[5]) {instance_eval('def _5; end')}
+    assert_warn(mesg[6]) {instance_eval('def self._6; end')}
     assert_raise_with_message(NameError, /undefined local variable or method `_1'/) {
       eval('_1')
     }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]