parse.y: adjust `void_expr_error()`; fix #5606

Allow void expression on some places e.g. right hand of `rescue`
modifier. In addition, checks added on some places, e.g. left hand of
logical operators.
parent 4e8d3764
...@@ -619,6 +619,7 @@ new_colon3(parser_state *p, mrb_sym c) ...@@ -619,6 +619,7 @@ new_colon3(parser_state *p, mrb_sym c)
static node* static node*
new_and(parser_state *p, node *a, node *b) new_and(parser_state *p, node *a, node *b)
{ {
void_expr_error(p, a);
return cons((node*)NODE_AND, cons(a, b)); return cons((node*)NODE_AND, cons(a, b));
} }
...@@ -626,6 +627,7 @@ new_and(parser_state *p, node *a, node *b) ...@@ -626,6 +627,7 @@ new_and(parser_state *p, node *a, node *b)
static node* static node*
new_or(parser_state *p, node *a, node *b) new_or(parser_state *p, node *a, node *b)
{ {
void_expr_error(p, a);
return cons((node*)NODE_OR, cons(a, b)); return cons((node*)NODE_OR, cons(a, b));
} }
...@@ -640,6 +642,7 @@ new_array(parser_state *p, node *a) ...@@ -640,6 +642,7 @@ new_array(parser_state *p, node *a)
static node* static node*
new_splat(parser_state *p, node *a) new_splat(parser_state *p, node *a)
{ {
void_expr_error(p, a);
return cons((node*)NODE_SPLAT, a); return cons((node*)NODE_SPLAT, a);
} }
...@@ -1763,7 +1766,6 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym ...@@ -1763,7 +1766,6 @@ stmt : keyword_alias fsym {p->lstate = EXPR_FNAME;} fsym
| arg tASSOC tIDENTIFIER | arg tASSOC tIDENTIFIER
{ {
node *lhs = new_lvar(p, $3); node *lhs = new_lvar(p, $3);
void_expr_error(p, $1);
assignable(p, lhs); assignable(p, lhs);
$$ = new_asgn(p, lhs, $1); $$ = new_asgn(p, lhs, $1);
} }
...@@ -1813,7 +1815,6 @@ command_asgn : lhs '=' command_rhs ...@@ -1813,7 +1815,6 @@ command_asgn : lhs '=' command_rhs
$$ = $1; $$ = $1;
endless_method_name(p, $1); endless_method_name(p, $1);
void_expr_error(p, $4); void_expr_error(p, $4);
void_expr_error(p, $6);
defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6)); defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p); nvars_unnest(p);
p->in_def--; p->in_def--;
...@@ -1831,7 +1832,6 @@ command_asgn : lhs '=' command_rhs ...@@ -1831,7 +1832,6 @@ command_asgn : lhs '=' command_rhs
{ {
$$ = $1; $$ = $1;
void_expr_error(p, $4); void_expr_error(p, $4);
void_expr_error(p, $6);
defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6)); defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p); nvars_unnest(p);
p->in_def--; p->in_def--;
...@@ -2448,7 +2448,6 @@ arg : lhs '=' arg_rhs ...@@ -2448,7 +2448,6 @@ arg : lhs '=' arg_rhs
$$ = $1; $$ = $1;
endless_method_name(p, $1); endless_method_name(p, $1);
void_expr_error(p, $4); void_expr_error(p, $4);
void_expr_error(p, $6);
defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6)); defn_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p); nvars_unnest(p);
p->in_def--; p->in_def--;
...@@ -2466,7 +2465,6 @@ arg : lhs '=' arg_rhs ...@@ -2466,7 +2465,6 @@ arg : lhs '=' arg_rhs
{ {
$$ = $1; $$ = $1;
void_expr_error(p, $4); void_expr_error(p, $4);
void_expr_error(p, $6);
defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6)); defs_setup(p, $$, $2, new_mod_rescue(p, $4, $6));
nvars_unnest(p); nvars_unnest(p);
p->in_def--; p->in_def--;
...@@ -2502,7 +2500,6 @@ arg_rhs : arg %prec tOP_ASGN ...@@ -2502,7 +2500,6 @@ arg_rhs : arg %prec tOP_ASGN
| arg modifier_rescue arg | arg modifier_rescue arg
{ {
void_expr_error(p, $1); void_expr_error(p, $1);
void_expr_error(p, $3);
$$ = new_mod_rescue(p, $1, $3); $$ = new_mod_rescue(p, $1, $3);
} }
; ;
...@@ -2630,7 +2627,6 @@ args : arg ...@@ -2630,7 +2627,6 @@ args : arg
} }
| tSTAR arg | tSTAR arg
{ {
void_expr_error(p, $2);
$$ = list1(new_splat(p, $2)); $$ = list1(new_splat(p, $2));
NODE_LINENO($$, $2); NODE_LINENO($$, $2);
} }
...@@ -2641,7 +2637,6 @@ args : arg ...@@ -2641,7 +2637,6 @@ args : arg
} }
| args comma tSTAR arg | args comma tSTAR arg
{ {
void_expr_error(p, $4);
$$ = push($1, new_splat(p, $4)); $$ = push($1, new_splat(p, $4));
} }
; ;
...@@ -2653,12 +2648,10 @@ mrhs : args comma arg ...@@ -2653,12 +2648,10 @@ mrhs : args comma arg
} }
| args comma tSTAR arg | args comma tSTAR arg
{ {
void_expr_error(p, $4);
$$ = push($1, new_splat(p, $4)); $$ = push($1, new_splat(p, $4));
} }
| tSTAR arg | tSTAR arg
{ {
void_expr_error(p, $2);
$$ = list1(new_splat(p, $2)); $$ = list1(new_splat(p, $2));
} }
; ;
...@@ -3682,6 +3675,7 @@ f_kw : f_label arg ...@@ -3682,6 +3675,7 @@ f_kw : f_label arg
f_block_kw : f_label primary_value f_block_kw : f_label primary_value
{ {
void_expr_error(p, $2);
$$ = new_kw_arg(p, $1, cons($2, locals_node(p))); $$ = new_kw_arg(p, $1, cons($2, locals_node(p)));
local_unnest(p); local_unnest(p);
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment