mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Fixed reserved numbered parameter warning
This commit is contained in:
parent
6180f1fede
commit
2698f13a1f
2 changed files with 8 additions and 3 deletions
10
parse.y
10
parse.y
|
@ -170,9 +170,13 @@ struct local_vars {
|
||||||
enum {
|
enum {
|
||||||
ORDINAL_PARAM = -1,
|
ORDINAL_PARAM = -1,
|
||||||
NO_PARAM = 0,
|
NO_PARAM = 0,
|
||||||
NUMPARAM_MAX = 100,
|
NUMPARAM_MAX = 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define NUMPARAM_ID_P(id) (is_local_id(id) && NUMPARAM_ID_TO_IDX(id) <= NUMPARAM_MAX)
|
||||||
|
#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - tNUMPARAM_0)
|
||||||
|
#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_0 + (idx)))
|
||||||
|
|
||||||
#define DVARS_INHERIT ((void*)1)
|
#define DVARS_INHERIT ((void*)1)
|
||||||
#define DVARS_TOPSCOPE NULL
|
#define DVARS_TOPSCOPE NULL
|
||||||
#define DVARS_TERMINAL_P(tbl) ((tbl) == DVARS_INHERIT || (tbl) == DVARS_TOPSCOPE)
|
#define DVARS_TERMINAL_P(tbl) ((tbl) == DVARS_INHERIT || (tbl) == DVARS_TOPSCOPE)
|
||||||
|
@ -11705,9 +11709,9 @@ arg_var(struct parser_params *p, ID id)
|
||||||
static void
|
static void
|
||||||
local_var(struct parser_params *p, ID id)
|
local_var(struct parser_params *p, ID id)
|
||||||
{
|
{
|
||||||
if (id >= idNUMPARAM_0 && id <= idNUMPARAM_9) {
|
if (NUMPARAM_ID_P(id)) {
|
||||||
rb_warn1("`_%d' is used as numbered parameter",
|
rb_warn1("`_%d' is used as numbered parameter",
|
||||||
WARN_I((int)(id - idNUMPARAM_0)));
|
WARN_I(NUMPARAM_ID_TO_IDX(id)));
|
||||||
}
|
}
|
||||||
vtable_add(p->lvtbl->vars, id);
|
vtable_add(p->lvtbl->vars, id);
|
||||||
if (p->lvtbl->used) {
|
if (p->lvtbl->used) {
|
||||||
|
|
|
@ -1459,6 +1459,7 @@ eom
|
||||||
assert_syntax_error('proc {@1_}', /unexpected/)
|
assert_syntax_error('proc {@1_}', /unexpected/)
|
||||||
assert_syntax_error('proc {@9999999999999999}', /too large/)
|
assert_syntax_error('proc {@9999999999999999}', /too large/)
|
||||||
assert_syntax_error('@1', /outside block/)
|
assert_syntax_error('@1', /outside block/)
|
||||||
|
assert_warn(/`_2' is used as numbered parameter/) {eval('_2=1')}
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_value_expr_in_condition
|
def test_value_expr_in_condition
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue