diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-04-19 22:19:41 +0900 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-08-30 12:39:31 -0700 |
commit | 6a9ce1fea89bc5c6518dd6bb7ff3b824a9321976 (patch) | |
tree | d1e954802cfcb8fafb71b2e16dd7d957326d70d7 /parse.y | |
parent | afae8555da07b2349a245d6646e3b36a49f027d5 (diff) |
Support **nil syntax for specifying a method does not accept keyword arguments
This syntax means the method should be treated as a method that
uses keyword arguments, but no specific keyword arguments are
supported, and therefore calling the method with keyword arguments
will raise an ArgumentError. It is still allowed to double splat
an empty hash when calling the method, as that does not pass
any keyword arguments.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2395
Diffstat (limited to 'parse.y')
-rw-r--r-- | parse.y | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -3245,6 +3245,10 @@ block_args_tail : f_block_kwarg ',' f_kwrest opt_f_block_arg { $$ = new_args_tail(p, Qnone, $1, $2, &@1); } + | f_no_kwarg opt_f_block_arg + { + $$ = new_args_tail(p, Qnone, rb_intern("nil"), $2, &@1); + } | f_block_arg { $$ = new_args_tail(p, Qnone, Qnone, $1, &@1); @@ -4712,6 +4716,10 @@ args_tail : f_kwarg ',' f_kwrest opt_f_block_arg { $$ = new_args_tail(p, Qnone, $1, $2, &@1); } + | f_no_kwarg opt_f_block_arg + { + $$ = new_args_tail(p, Qnone, rb_intern("nil"), $2, &@1); + } | f_block_arg { $$ = new_args_tail(p, Qnone, Qnone, $1, &@1); @@ -4968,6 +4976,9 @@ kwrest_mark : tPOW | tDSTAR ; +f_no_kwarg : kwrest_mark keyword_nil + ; + f_kwrest : kwrest_mark tIDENTIFIER { arg_var(p, shadowing_lvar(p, get_id($2))); @@ -11125,6 +11136,9 @@ new_args_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, ID block, args->kw_rest_arg = NEW_DVAR(kw_rest_arg, loc); args->kw_rest_arg->nd_cflag = kw_bits; } + else if (kw_rest_arg == rb_intern("nil")) { + args->no_kwarg = 1; + } else if (kw_rest_arg) { args->kw_rest_arg = NEW_DVAR(kw_rest_arg, loc); } |