1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Warn also numbered parameter like methods

This commit is contained in:
Nobuyoshi Nakada 2019-12-20 08:18:19 +09:00
parent 3816cd945d
commit 2898367b3a
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 5 additions and 0 deletions

View file

@ -188,6 +188,7 @@ numparam_id_p(ID id)
unsigned int idx = NUMPARAM_ID_TO_IDX(id);
return idx > 0 && idx <= NUMPARAM_MAX;
}
static void numparam_name(struct parser_params *p, ID id);
#define DVARS_INHERIT ((void*)1)
#define DVARS_TOPSCOPE NULL
@ -2981,6 +2982,7 @@ primary : literal
}
| k_def fname
{
numparam_name(p, get_id($2));
local_push(p, 0);
$<id>$ = p->cur_arg;
p->cur_arg = 0;
@ -3007,6 +3009,7 @@ primary : literal
}
| k_def singleton dot_or_colon {SET_LEX_STATE(EXPR_FNAME);} fname
{
numparam_name(p, get_id($5));
$<num>4 = p->in_def;
p->in_def = 1;
SET_LEX_STATE(EXPR_ENDFN|EXPR_LABEL); /* force for args */

View file

@ -1441,6 +1441,8 @@ eom
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')}
assert_raise_with_message(NameError, /undefined local variable or method `_1'/) {
eval('_1')
}