Bug #5303

parse.y relies on $$ = $1 before action routines [PATCH]

Added by Michael Edgar over 3 years ago. Updated over 3 years ago.

[ruby-core:39429]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 1.9.3dev (2011-08-21 revision 33020) [x86_64-darwin11.1.0] Backport:

Description

In perusing parse.y, I came across this pair of action routines:

bv_decls : bvar
/*%c%*/
/*%c
{
$$ = rb_ary_new3(1, $1);
}
%*/
| bv_decls ',' bvar
/*%c%*/
/*%c
{
rb_ary_push($$, $3);
}
%*/
;

Here, the call to rb_ary_push($$, $3) is relying on the fact that yacc/bison prefaces each routine's execution with $$=$1. It does so in order to implement the default behavior for rules that have no action routine (the implicit $$ = $1 rule), and while I doubt that will ever change, I don't think it should be relied upon. At the very least, it's a bit confusing at first glance (using $$ before it is set). Notably, other instances of this idiom (undef_list -> fitem | undef_list ',' fitem; f_arg -> f_arg_item | f_arg ',' f_arg_item; f_block_optarg; f_optarg....) use this approach.

It is corrected by simply replacing $$ with $1. A patch is included. No behavior changes, so no test is included.

parse_y.diff Magnifier (272 Bytes) Michael Edgar, 09/09/2011 11:38 PM

Associated revisions

Revision 33242
Added by Yukihiro Matsumoto over 3 years ago

  • parse.y (bv_decls): parse.y relies on $$ = $1 before action routines. a patch from Michael Edgar. [Bug #5303]

Revision 33242
Added by Yukihiro Matsumoto over 3 years ago

  • parse.y (bv_decls): parse.y relies on $$ = $1 before action routines. a patch from Michael Edgar. [Bug #5303]

History

#1 Updated by Yukihiro Matsumoto over 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33242.
Michael, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • parse.y (bv_decls): parse.y relies on $$ = $1 before action routines. a patch from Michael Edgar. [Bug #5303]

Also available in: Atom PDF