Skip to content

Commit 2dd2018

Browse files
committed
Reject return and similar with block pass argument
Same handling as for `yield`. Fixes [Bug #21988]
1 parent 55cd647 commit 2dd2018

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/prism.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19685,6 +19685,15 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, u
1968519685
PM_PARSER_ERR_TOKEN_FORMAT(parser, &next, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_str(next.type));
1968619686
}
1968719687
}
19688+
19689+
// It's possible that we've parsed a block argument through our
19690+
// call to parse_arguments. If we found one, we should mark it
19691+
// as invalid and destroy it, as we don't have a place for it.
19692+
if (arguments.block != NULL) {
19693+
pm_parser_err_node(parser, arguments.block, PM_ERR_UNEXPECTED_BLOCK_ARGUMENT);
19694+
pm_node_unreference(parser, arguments.block);
19695+
arguments.block = NULL;
19696+
}
1968819697
}
1968919698

1969019699
switch (keyword.type) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
return &b
2+
^ unexpected '&', expecting end-of-input
3+
^ unexpected '&', ignoring it
4+
5+
return(&b)
6+
^ unexpected '&', ignoring it
7+
^ unexpected '&', expecting end-of-input
8+
^ unexpected '&', ignoring it
9+
^ expected a matching `)`
10+
^ unexpected '&', expecting end-of-input
11+
^ unexpected '&', ignoring it
12+
^ unexpected ')', expecting end-of-input
13+
^ unexpected ')', ignoring it
14+
15+
return a, &b
16+
^~ block argument should not be given
17+
18+
return(a, &b)
19+
^~ unexpected write target
20+
^ unexpected '&', expecting end-of-input
21+
^ unexpected '&', ignoring it
22+
^ expected a matching `)`
23+
^ unexpected '&', expecting end-of-input
24+
^ unexpected '&', ignoring it
25+
^ unexpected ')', expecting end-of-input
26+
^ unexpected ')', ignoring it
27+
28+
tap { break a, &b }
29+
^~ block argument should not be given
30+
31+
tap { next a, &b }
32+
^~ block argument should not be given
33+

0 commit comments

Comments
 (0)