ruby-changes:59335
From: Nobuyoshi <ko1@a...>
Date: Fri, 20 Dec 2019 08:18:46 +0900 (JST)
Subject: [ruby-changes:59335] 2898367b3a (master): Warn also numbered parameter like methods
https://git.ruby-lang.org/ruby.git/commit/?id=2898367b3a From 2898367b3a1de00ca78067cc17dd4d1f8df37778 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 20 Dec 2019 08:18:19 +0900 Subject: Warn also numbered parameter like methods diff --git a/parse.y b/parse.y index 33c1c89..7247afa 100644 --- a/parse.y +++ b/parse.y @@ -188,6 +188,7 @@ numparam_id_p(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L188 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L2982 } | 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 https://github.com/ruby/ruby/blob/trunk/parse.y#L3009 } | 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 */ diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index b292b24..5eb69c5 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1441,6 +1441,8 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1441 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') } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/