ruby-changes:59332
From: Nobuyoshi <ko1@a...>
Date: Fri, 20 Dec 2019 01:37:08 +0900 (JST)
Subject: [ruby-changes:59332] 27ddb6e998 (master): Warn also numbered parameter like parameters
https://git.ruby-lang.org/ruby.git/commit/?id=27ddb6e998 From 27ddb6e99848c397a415b785315896ab50308076 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 20 Dec 2019 01:01:17 +0900 Subject: Warn also numbered parameter like parameters [Feature #16433] diff --git a/parse.y b/parse.y index 7de84ee..33c1c89 100644 --- a/parse.y +++ b/parse.y @@ -11830,18 +11830,24 @@ node_newnode_with_locals(struct parser_params *p, enum node_type type, VALUE a1, https://github.com/ruby/ruby/blob/trunk/parse.y#L11830 #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 arg_var(struct parser_params *p, ID id) { + numparam_name(p, id); vtable_add(p->lvtbl->args, id); } static void local_var(struct parser_params *p, ID id) { - if (NUMPARAM_ID_P(id)) { - rb_warn1("`_%d' is used as numbered parameter", - WARN_I(NUMPARAM_ID_TO_IDX(id))); - } + numparam_name(p, id); vtable_add(p->lvtbl->vars, id); if (p->lvtbl->used) { vtable_add(p->lvtbl->used, (ID)p->ruby_sourceline); diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index ffe2ea1..cef584c 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -31,7 +31,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L31 alias compile_error on_error 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 def test_tokenize diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 286beb7..b292b24 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1439,6 +1439,8 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1439 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(/`_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'/) { eval('_1') } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/