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

ruby-changes:59341

From: Nobuyoshi <ko1@a...>
Date: Fri, 20 Dec 2019 15:02:33 +0900 (JST)
Subject: [ruby-changes:59341] 7a94225e7d (master): Refined the warning message for numbered-parameter like variables

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

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

[Bug #16438]

diff --git a/NEWS b/NEWS
index bfd93a4..e0efad8 100644
--- a/NEWS
+++ b/NEWS
@@ -127,7 +127,7 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS#L127
 
   You can still define a local variable named _1 and so on, and that is honored when present, but renders warning.
 
-    _1 = 0            #=> warning: `_1' is used as numbered parameter
+    _1 = 0            #=> warning: `_1' is reserved for numbered parameter; consider another name
     [1].each { p _1 } # prints 0 instead of 1
 
 ==== proc/lambda without block is deprecated
diff --git a/parse.y b/parse.y
index 05e2c1d..9f7e3a6 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 reserved as numbered parameter",
+    rb_warn1("`_%d' is reserved for numbered parameter; consider another name",
 	     WARN_I(NUMPARAM_ID_TO_IDX(id)));
 }
 
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 540ab7b..d50c325 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1437,7 +1437,7 @@ 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/)
-    mesg = proc {|n| /`_#{n}' is reserved as numbered parameter/}
+    mesg = proc {|n| /`_#{n}' is reserved for numbered parameter/}
     assert_warn(mesg[1]) {eval('proc {_1 = nil}')}
     assert_warn(mesg[2]) {eval('_2=1')}
     assert_warn(mesg[3]) {eval('proc {|_3|}')}
-- 
cgit v0.10.2


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

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