Commit 4654db4f authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2096 from nobu/def_in_cmdarg

Def in cmdarg
parents 5f846923 9eaddfab
...@@ -997,7 +997,7 @@ heredoc_end(parser_state *p) ...@@ -997,7 +997,7 @@ heredoc_end(parser_state *p)
node *nd; node *nd;
mrb_sym id; mrb_sym id;
int num; int num;
unsigned int stack; stack_type stack;
const struct vtable *vars; const struct vtable *vars;
} }
...@@ -2226,6 +2226,8 @@ primary : literal ...@@ -2226,6 +2226,8 @@ primary : literal
{ {
p->in_def++; p->in_def++;
$<nd>$ = local_switch(p); $<nd>$ = local_switch(p);
$<stack>1 = p->cmdarg_stack;
p->cmdarg_stack = 0;
} }
f_arglist f_arglist
bodystmt bodystmt
...@@ -2234,12 +2236,15 @@ primary : literal ...@@ -2234,12 +2236,15 @@ primary : literal
$$ = new_def(p, $2, $4, $5); $$ = new_def(p, $2, $4, $5);
local_resume(p, $<nd>3); local_resume(p, $<nd>3);
p->in_def--; p->in_def--;
p->cmdarg_stack = $<stack>1;
} }
| keyword_def singleton dot_or_colon {p->lstate = EXPR_FNAME;} fname | keyword_def singleton dot_or_colon {p->lstate = EXPR_FNAME;} fname
{ {
p->in_single++; p->in_single++;
p->lstate = EXPR_ENDFN; /* force for args */ p->lstate = EXPR_ENDFN; /* force for args */
$<nd>$ = local_switch(p); $<nd>$ = local_switch(p);
$<stack>1 = p->cmdarg_stack;
p->cmdarg_stack = 0;
} }
f_arglist f_arglist
bodystmt bodystmt
...@@ -2248,6 +2253,7 @@ primary : literal ...@@ -2248,6 +2253,7 @@ primary : literal
$$ = new_sdef(p, $2, $5, $7, $8); $$ = new_sdef(p, $2, $5, $7, $8);
local_resume(p, $<nd>6); local_resume(p, $<nd>6);
p->in_single--; p->in_single--;
p->cmdarg_stack = $<stack>1;
} }
| keyword_break | keyword_break
{ {
......
...@@ -265,3 +265,10 @@ assert('parenthesed do-block in cmdarg') do ...@@ -265,3 +265,10 @@ assert('parenthesed do-block in cmdarg') do
result = x.test (proc do :ok; end) result = x.test (proc do :ok; end)
assert_equal :ok, result assert_equal :ok, result
end end
assert('method definition in cmdarg') do
if false
bar def foo; self.each do end end
end
true
end
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