Skip to content

Commit a52588f

Browse files
committed
Correct the "ambiguous first argument" condition
Fix #2182 This change reflects this line: https://github.com/ruby/ruby/blob/6283ae8d369bd2f8a022bb69bc5b742c58529dec/parse.y#L11124.
1 parent 5f46d36 commit a52588f

File tree

3 files changed

+121
-102
lines changed

3 files changed

+121
-102
lines changed

src/prism.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8972,11 +8972,12 @@ parser_lex(pm_parser_t *parser) {
89728972
}
89738973

89748974
bool spcarg = lex_state_spcarg_p(parser, space_seen);
8975-
if (spcarg) {
8975+
bool is_beg = lex_state_beg_p(parser);
8976+
if (!is_beg && spcarg) {
89768977
pm_parser_warn_token(parser, &parser->current, PM_WARN_AMBIGUOUS_FIRST_ARGUMENT_MINUS);
89778978
}
89788979

8979-
if (lex_state_beg_p(parser) || spcarg) {
8980+
if (is_beg || spcarg) {
89808981
lex_state_set(parser, PM_LEX_STATE_BEG);
89818982
LEX(pm_char_is_decimal_digit(peek(parser)) ? PM_TOKEN_UMINUS_NUM : PM_TOKEN_UMINUS);
89828983
}

test/prism/fixtures/hashes.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ tap do
2424
b = 1
2525
{ a:, b:, c:, D: }
2626
end
27+
28+
{ a: -1 }

test/prism/snapshots/hashes.txt

Lines changed: 116 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)