Numbered parameters should not be available in the lambda bodies.

`mruby` does not warn like `CRuby` for cases like #4893.
Fix #4890, fix #4891, fix #4893.
parent 2fe78a0c
...@@ -838,7 +838,7 @@ new_block_arg(parser_state *p, node *a) ...@@ -838,7 +838,7 @@ new_block_arg(parser_state *p, node *a)
} }
static node* static node*
setup_args(parser_state *p, node *a) setup_numparams(parser_state *p, node *a)
{ {
int nvars = intn(p->nvars->cdr); int nvars = intn(p->nvars->cdr);
if (nvars > 0) { if (nvars > 0) {
...@@ -847,7 +847,8 @@ setup_args(parser_state *p, node *a) ...@@ -847,7 +847,8 @@ setup_args(parser_state *p, node *a)
// m || opt || rest || tail // m || opt || rest || tail
if (a && (a->car || (a->cdr && a->cdr->car) || (a->cdr->cdr && a->cdr->cdr->car) || (a->cdr->cdr->cdr->cdr && a->cdr->cdr->cdr->cdr->car))) { if (a && (a->car || (a->cdr && a->cdr->car) || (a->cdr->cdr && a->cdr->cdr->car) || (a->cdr->cdr->cdr->cdr && a->cdr->cdr->cdr->cdr->car))) {
yyerror(p, "ordinary parameter is defined"); yyerror(p, "ordinary parameter is defined");
} else { }
else {
node* args = 0; node* args = 0;
for (i = nvars; i > 0; i--) { for (i = nvars; i > 0; i--) {
char buf[3]; char buf[3];
...@@ -869,7 +870,7 @@ setup_args(parser_state *p, node *a) ...@@ -869,7 +870,7 @@ setup_args(parser_state *p, node *a)
static node* static node*
new_block(parser_state *p, node *a, node *b) new_block(parser_state *p, node *a, node *b)
{ {
a = setup_args(p, a); a = setup_numparams(p, a);
return list4((node*)NODE_BLOCK, locals_node(p), a, b); return list4((node*)NODE_BLOCK, locals_node(p), a, b);
} }
...@@ -877,7 +878,6 @@ new_block(parser_state *p, node *a, node *b) ...@@ -877,7 +878,6 @@ new_block(parser_state *p, node *a, node *b)
static node* static node*
new_lambda(parser_state *p, node *a, node *b) new_lambda(parser_state *p, node *a, node *b)
{ {
a = setup_args(p, a);
return list4((node*)NODE_LAMBDA, locals_node(p), a, b); return list4((node*)NODE_LAMBDA, locals_node(p), a, b);
} }
...@@ -2480,7 +2480,6 @@ primary : literal ...@@ -2480,7 +2480,6 @@ primary : literal
| tLAMBDA | tLAMBDA
{ {
local_nest(p); local_nest(p);
nvars_nest(p);
$<num>$ = p->lpar_beg; $<num>$ = p->lpar_beg;
p->lpar_beg = ++p->paren_nest; p->lpar_beg = ++p->paren_nest;
} }
...@@ -2494,7 +2493,6 @@ primary : literal ...@@ -2494,7 +2493,6 @@ primary : literal
p->lpar_beg = $<num>2; p->lpar_beg = $<num>2;
$$ = new_lambda(p, $3, $5); $$ = new_lambda(p, $3, $5);
local_unnest(p); local_unnest(p);
nvars_unnest(p);
p->cmdarg_stack = $<stack>4; p->cmdarg_stack = $<stack>4;
CMDARG_LEXPOP(); CMDARG_LEXPOP();
} }
......
...@@ -674,9 +674,6 @@ end ...@@ -674,9 +674,6 @@ end
assert('numbered parameters') do assert('numbered parameters') do
assert_equal(15, [1,2,3,4,5].reduce {_1+_2}) assert_equal(15, [1,2,3,4,5].reduce {_1+_2})
assert_equal(3, ->{_1+_2}.call(1,2))
assert_equal(4, ->(a=->{_1}){a}.call.call(4))
assert_equal(5, -> a: ->{_1} {a}.call.call(5))
assert_equal(45, Proc.new do _1 + _2 + _3 + _4 + _5 + _6 + _7 + _8 + _9 end.call(*[1, 2, 3, 4, 5, 6, 7, 8, 9])) assert_equal(45, Proc.new do _1 + _2 + _3 + _4 + _5 + _6 + _7 + _8 + _9 end.call(*[1, 2, 3, 4, 5, 6, 7, 8, 9]))
end 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