Refined the warning message for numbered-parameter like variables

[Bug #16438]
This commit is contained in:
Nobuyoshi Nakada 2019-12-20 14:54:44 +09:00
Родитель a8bddb3a18
Коммит 7a94225e7d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4BC7D6DF58D8DF60
3 изменённых файлов: 3 добавлений и 3 удалений

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.
_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

Просмотреть файл

@ -11836,7 +11836,7 @@ static void
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)));
}

Просмотреть файл

@ -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('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|}')}