Skip to content

Commit

Permalink
[ruby/prism] Add an error for in keyword in arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and matzbot committed Dec 15, 2023
1 parent 04f7be6 commit 16830a4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions prism/diagnostic.c
Expand Up @@ -62,6 +62,7 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
[PM_ERR_ARGUMENT_FORMAL_GLOBAL] = "invalid formal argument; formal argument cannot be a global variable",
[PM_ERR_ARGUMENT_FORMAL_IVAR] = "invalid formal argument; formal argument cannot be an instance variable",
[PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = "unexpected `...` in an non-parenthesized call",
[PM_ERR_ARGUMENT_IN] = "unexpected `in` keyword in arguments",
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = "unexpected `&` when the parent method is not forwarding",
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = "unexpected `...` when the parent method is not forwarding",
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = "unexpected `*` when the parent method is not forwarding",
Expand Down
1 change: 1 addition & 0 deletions prism/diagnostic.h
Expand Up @@ -53,6 +53,7 @@ typedef enum {
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
PM_ERR_ARGUMENT_FORMAL_IVAR,
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
PM_ERR_ARGUMENT_IN,
PM_ERR_ARGUMENT_NO_FORWARDING_AMP,
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
Expand Down
2 changes: 2 additions & 0 deletions prism/prism.c
Expand Up @@ -11338,6 +11338,8 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
}

parsed_bare_hash = true;
} else if (accept1(parser, PM_TOKEN_KEYWORD_IN)) {
pm_parser_err_current(parser, PM_ERR_ARGUMENT_IN);
}

parse_arguments_append(parser, arguments, argument);
Expand Down
15 changes: 15 additions & 0 deletions test/prism/errors_test.rb
Expand Up @@ -1997,6 +1997,21 @@ def test_range_and_bin_op
end
end

def test_command_call_in
source = <<~RUBY
foo 1 in a
a = foo 2 in b
RUBY
message1 = 'unexpected `in` keyword in arguments'
message2 = 'expected a newline or semicolon after the statement'
assert_errors expression(source), source, [
[message1, 9..10],
[message2, 8..8],
[message1, 24..25],
[message2, 23..23],
]
end

def test_constant_assignment_in_method
source = 'def foo();A=1;end'
assert_errors expression(source), source, [
Expand Down

0 comments on commit 16830a4

Please sign in to comment.