mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
c6c67254fb
commit
27ddb6e998
3 changed files with 13 additions and 5 deletions
14
parse.y
14
parse.y
|
@ -11829,19 +11829,25 @@ node_newnode_with_locals(struct parser_params *p, enum node_type type, VALUE a1,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
numparam_name(struct parser_params *p, ID id)
|
||||||
|
{
|
||||||
|
if (!NUMPARAM_ID_P(id)) return;
|
||||||
|
rb_warn1("`_%d' is used as numbered parameter",
|
||||||
|
WARN_I(NUMPARAM_ID_TO_IDX(id)));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
arg_var(struct parser_params *p, ID id)
|
arg_var(struct parser_params *p, ID id)
|
||||||
{
|
{
|
||||||
|
numparam_name(p, id);
|
||||||
vtable_add(p->lvtbl->args, id);
|
vtable_add(p->lvtbl->args, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
local_var(struct parser_params *p, ID id)
|
local_var(struct parser_params *p, ID id)
|
||||||
{
|
{
|
||||||
if (NUMPARAM_ID_P(id)) {
|
numparam_name(p, id);
|
||||||
rb_warn1("`_%d' is used as numbered parameter",
|
|
||||||
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) {
|
||||||
vtable_add(p->lvtbl->used, (ID)p->ruby_sourceline);
|
vtable_add(p->lvtbl->used, (ID)p->ruby_sourceline);
|
||||||
|
|
|
@ -31,7 +31,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
||||||
alias compile_error on_error
|
alias compile_error on_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
lexer.lex.select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok }
|
lexer.lex.select {|_,type,_| type == sym }.map {|_,_,tok| tok }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tokenize
|
def test_tokenize
|
||||||
|
|
|
@ -1439,6 +1439,8 @@ eom
|
||||||
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/)
|
||||||
assert_warn(/`_1' is used as numbered parameter/) {eval('proc {_1 = nil}')}
|
assert_warn(/`_1' is used as numbered parameter/) {eval('proc {_1 = nil}')}
|
||||||
assert_warn(/`_2' is used as numbered parameter/) {eval('_2=1')}
|
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_raise_with_message(NameError, /undefined local variable or method `_1'/) {
|
assert_raise_with_message(NameError, /undefined local variable or method `_1'/) {
|
||||||
eval('_1')
|
eval('_1')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue