Skip to content

Commit 674ffbb

Browse files
committed
Fix error message for block/lambda with ... argument
They currently complain that the parent method is not forwarding. But the actual problem is that these types of arguments simply don't accept `...` Fixes [Bug #21927]
1 parent 5446f7b commit 674ffbb

5 files changed

Lines changed: 51 additions & 5 deletions

File tree

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ errors:
1717
- ARGUMENT_FORWARDING_UNBOUND
1818
- ARGUMENT_NO_FORWARDING_AMPERSAND
1919
- ARGUMENT_NO_FORWARDING_ELLIPSES
20+
- ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA
21+
- ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK
2022
- ARGUMENT_NO_FORWARDING_STAR
2123
- ARGUMENT_NO_FORWARDING_STAR_STAR
2224
- ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT

src/prism.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14636,6 +14636,7 @@ parse_parameters(
1463614636
bool allows_forwarding_parameters,
1463714637
bool accepts_blocks_in_defaults,
1463814638
bool in_block,
14639+
pm_diagnostic_id_t diag_id_forwarding,
1463914640
uint16_t depth
1464014641
) {
1464114642
pm_do_loop_stack_push(parser, false);
@@ -14695,7 +14696,7 @@ parse_parameters(
1469514696
}
1469614697
case PM_TOKEN_UDOT_DOT_DOT: {
1469714698
if (!allows_forwarding_parameters) {
14698-
pm_parser_err_current(parser, PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES);
14699+
pm_parser_err_current(parser, diag_id_forwarding);
1469914700
}
1470014701

1470114702
bool succeeded = update_parameter_state(parser, &parser->current, &order);
@@ -15388,6 +15389,7 @@ parse_block_parameters(
1538815389
false,
1538915390
accepts_blocks_in_defaults,
1539015391
true,
15392+
is_lambda_literal ? PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA : PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK,
1539115393
(uint16_t) (depth + 1)
1539215394
);
1539315395
}
@@ -19585,7 +19587,17 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1958519587
if (match1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
1958619588
params = NULL;
1958719589
} else {
19588-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, true, false, true, true, false, (uint16_t) (depth + 1));
19590+
params = parse_parameters(
19591+
parser,
19592+
PM_BINDING_POWER_DEFINED,
19593+
true,
19594+
false,
19595+
true,
19596+
true,
19597+
false,
19598+
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
19599+
(uint16_t) (depth + 1)
19600+
);
1958919601
}
1959019602

1959119603
lex_state_set(parser, PM_LEX_STATE_BEG);
@@ -19610,7 +19622,17 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1961019622

1961119623
lparen = not_provided(parser);
1961219624
rparen = not_provided(parser);
19613-
params = parse_parameters(parser, PM_BINDING_POWER_DEFINED, false, false, true, true, false, (uint16_t) (depth + 1));
19625+
params = parse_parameters(
19626+
parser,
19627+
PM_BINDING_POWER_DEFINED,
19628+
false,
19629+
false,
19630+
true,
19631+
true,
19632+
false,
19633+
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
19634+
(uint16_t) (depth + 1)
19635+
);
1961419636

1961519637
context_pop(parser);
1961619638
break;

templates/src/diagnostic.c.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
102102
[PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = { "unexpected `...` in an non-parenthesized call", PM_ERROR_LEVEL_SYNTAX },
103103
[PM_ERR_ARGUMENT_NO_FORWARDING_AMPERSAND] = { "unexpected `&`; no anonymous block parameter", PM_ERROR_LEVEL_SYNTAX },
104104
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = { "unexpected ... when the parent method is not forwarding", PM_ERROR_LEVEL_SYNTAX },
105+
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_LAMBDA] = { "unexpected ... in lambda argument", PM_ERROR_LEVEL_SYNTAX },
106+
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES_BLOCK] = { "unexpected ... in block argument", PM_ERROR_LEVEL_SYNTAX },
105107
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = { "unexpected `*`; no anonymous rest parameter", PM_ERROR_LEVEL_SYNTAX },
106108
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR_STAR] = { "unexpected `**`; no anonymous keyword rest parameter", PM_ERROR_LEVEL_SYNTAX },
107109
[PM_ERR_ARGUMENT_SPLAT_AFTER_ASSOC_SPLAT] = { "unexpected `*` splat argument after a `**` keyword splat argument", PM_ERROR_LEVEL_SYNTAX },
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
a {|...|}
2-
^~~ unexpected ... when the parent method is not forwarding
2+
^~~ unexpected ... in block argument
3+
4+
def foo(...)
5+
a {|...|}
6+
^~~ unexpected ... in block argument
7+
end
8+
9+
def foo
10+
a {|...|}
11+
^~~ unexpected ... in block argument
12+
end
313

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
->(...) {}
2-
^~~ unexpected ... when the parent method is not forwarding
2+
^~~ unexpected ... in lambda argument
3+
4+
def foo(...)
5+
->(...) {}
6+
^~~ unexpected ... in lambda argument
7+
end
8+
9+
def foo
10+
->(...) {}
11+
^~~ unexpected ... in lambda argument
12+
end
313

0 commit comments

Comments
 (0)