From ead9b197be96f9eacf462b5539f71c43422495d0 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 12 Jul 2006 11:10:22 +0000 Subject: * parse.y (f_args): allow post mandatory arguments after optional arguments. [ruby-dev:29014] * parse.y (new_args_gen): allow post_args without rest_args. * eval.c (formal_assign): ditto. * parse.y (new_args_gen): check post argument duplication. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- parse.y | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'parse.y') diff --git a/parse.y b/parse.y index e26fc1eb66..c2d796eaf7 100644 --- a/parse.y +++ b/parse.y @@ -3941,6 +3941,14 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg $$ = dispatch5(params, $1, $3, Qnil, Qnil, escape_Qundef($4)); %*/ } + | f_arg ',' f_optarg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args($1, $3, 0, $5, $6); + /*% + $$ = dispatch5(params, $1, $3, Qnil, $5, escape_Qundef($6)); + %*/ + } | f_arg ',' f_rest_arg opt_f_block_arg { /*%%%*/ @@ -3989,6 +3997,14 @@ f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg $$ = dispatch5(params, Qnil, $1, Qnil, Qnil, escape_Qundef($2)); %*/ } + | f_optarg ',' f_post_arg opt_f_block_arg + { + /*%%%*/ + $$ = new_args(0, $1, 0, $3, $4); + /*% + $$ = dispatch5(params, Qnil, $1, Qnil, $3, escape_Qundef($4)); + %*/ + } | f_rest_arg opt_f_block_arg { /*%%%*/ @@ -4089,7 +4105,7 @@ f_arg : f_norm_arg VALUE arg = ID2SYM($3); $$ = $1; if (rb_ary_includes($$, arg)) { - yyerror("duplicated argument arg"); + yyerror("duplicated argument name"); } rb_ary_push($$, arg); /*% @@ -7898,9 +7914,18 @@ new_args_gen(struct parser_params *parser, VALUE m, NODE *o, NODE *r, NODE *p, N yyerror("duplicated rest argument name"); return 0; } - if (p) { - r = NEW_POSTARG(r, p); + } + if (p) { + node = p; + while (node) { + if (!node->nd_head) break; + if (arg_dup_check(node->nd_head->nd_vid, m, list, node)) { + yyerror("duplicated argument name"); + return 0; + } + node = node->nd_next; } + r = NEW_POSTARG(r, p); } node = NEW_ARGS(m, o, r); if (b) { -- cgit v1.2.3