summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-12-21 22:41:32 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-12-21 22:41:32 +0900
commit06e09fc7a9e88b677ec2f7b2806975536c9a104d (patch)
tree84fce725f6a452717872a3b96e08107048c257fd
parent2fe78a0c7c4456496ce54a4dc4ed38d8ef1ce664 (diff)
downloadmruby-06e09fc7a9e88b677ec2f7b2806975536c9a104d.tar.gz
mruby-06e09fc7a9e88b677ec2f7b2806975536c9a104d.zip
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.
-rw-r--r--mrbgems/mruby-compiler/core/parse.y10
-rw-r--r--test/t/syntax.rb3
2 files changed, 4 insertions, 9 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 2580b7ba5..6abc6d820 100644
--- a/mrbgems/mruby-compiler/core/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
@@ -838,7 +838,7 @@ new_block_arg(parser_state *p, node *a)
}
static node*
-setup_args(parser_state *p, node *a)
+setup_numparams(parser_state *p, node *a)
{
int nvars = intn(p->nvars->cdr);
if (nvars > 0) {
@@ -847,7 +847,8 @@ setup_args(parser_state *p, node *a)
// 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))) {
yyerror(p, "ordinary parameter is defined");
- } else {
+ }
+ else {
node* args = 0;
for (i = nvars; i > 0; i--) {
char buf[3];
@@ -869,7 +870,7 @@ setup_args(parser_state *p, node *a)
static node*
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);
}
@@ -877,7 +878,6 @@ new_block(parser_state *p, node *a, node *b)
static node*
new_lambda(parser_state *p, node *a, node *b)
{
- a = setup_args(p, a);
return list4((node*)NODE_LAMBDA, locals_node(p), a, b);
}
@@ -2480,7 +2480,6 @@ primary : literal
| tLAMBDA
{
local_nest(p);
- nvars_nest(p);
$<num>$ = p->lpar_beg;
p->lpar_beg = ++p->paren_nest;
}
@@ -2494,7 +2493,6 @@ primary : literal
p->lpar_beg = $<num>2;
$$ = new_lambda(p, $3, $5);
local_unnest(p);
- nvars_unnest(p);
p->cmdarg_stack = $<stack>4;
CMDARG_LEXPOP();
}
diff --git a/test/t/syntax.rb b/test/t/syntax.rb
index 4404de4d4..436c06601 100644
--- a/test/t/syntax.rb
+++ b/test/t/syntax.rb
@@ -674,9 +674,6 @@ end
assert('numbered parameters') do
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]))
end