зеркало из https://github.com/github/ruby.git
Refined the warning message for numbered-parameter like variables
[Bug #16438]
This commit is contained in:
Родитель
a8bddb3a18
Коммит
7a94225e7d
2
NEWS
2
NEWS
|
@ -127,7 +127,7 @@ sufficient information, see the ChangeLog file or Redmine
|
||||||
|
|
||||||
You can still define a local variable named _1 and so on, and that is honored when present, but renders warning.
|
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
|
[1].each { p _1 } # prints 0 instead of 1
|
||||||
|
|
||||||
==== proc/lambda without block is deprecated
|
==== proc/lambda without block is deprecated
|
||||||
|
|
2
parse.y
2
parse.y
|
@ -11836,7 +11836,7 @@ static void
|
||||||
numparam_name(struct parser_params *p, ID id)
|
numparam_name(struct parser_params *p, ID id)
|
||||||
{
|
{
|
||||||
if (!NUMPARAM_ID_P(id)) return;
|
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)));
|
WARN_I(NUMPARAM_ID_TO_IDX(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1437,7 +1437,7 @@ eom
|
||||||
assert_syntax_error('-> {_1; -> {_2}}', /numbered parameter is already used/)
|
assert_syntax_error('-> {_1; -> {_2}}', /numbered parameter is already used/)
|
||||||
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_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[1]) {eval('proc {_1 = nil}')}
|
||||||
assert_warn(mesg[2]) {eval('_2=1')}
|
assert_warn(mesg[2]) {eval('_2=1')}
|
||||||
assert_warn(mesg[3]) {eval('proc {|_3|}')}
|
assert_warn(mesg[3]) {eval('proc {|_3|}')}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче