Skip to content

Commit

Permalink
Reverse-sync CRuby
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jun 7, 2024
1 parent 90d570a commit 8b54e16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -14394,7 +14394,7 @@ parse_parameters(
context_push(parser, PM_CONTEXT_DEFAULT_PARAMS);

pm_constant_id_t name_id = pm_parser_constant_id_token(parser, &name);
uint32_t reads = pm_locals_reads(&parser->current_scope->locals, name_id);
uint32_t reads = parser->version == PM_OPTIONS_VERSION_CRUBY_3_3 ? pm_locals_reads(&parser->current_scope->locals, name_id) : 0;

pm_node_t *value = parse_value_expression(parser, binding_power, false, PM_ERR_PARAMETER_NO_DEFAULT);
pm_optional_parameter_node_t *param = pm_optional_parameter_node_create(parser, &name, &operator, value);
Expand All @@ -14407,7 +14407,7 @@ parse_parameters(
// If the value of the parameter increased the number of
// reads of that parameter, then we need to warn that we
// have a circular definition.
if (pm_locals_reads(&parser->current_scope->locals, name_id) != reads) {
if ((parser->version == PM_OPTIONS_VERSION_CRUBY_3_3) && (pm_locals_reads(&parser->current_scope->locals, name_id) != reads)) {
PM_PARSER_ERR_TOKEN_FORMAT_CONTENT(parser, name, PM_ERR_PARAMETER_CIRCULAR);
}

Expand Down Expand Up @@ -14486,10 +14486,10 @@ parse_parameters(
context_push(parser, PM_CONTEXT_DEFAULT_PARAMS);

pm_constant_id_t name_id = pm_parser_constant_id_token(parser, &local);
uint32_t reads = pm_locals_reads(&parser->current_scope->locals, name_id);
uint32_t reads = parser->version == PM_OPTIONS_VERSION_CRUBY_3_3 ? pm_locals_reads(&parser->current_scope->locals, name_id) : 0;
pm_node_t *value = parse_value_expression(parser, binding_power, false, PM_ERR_PARAMETER_NO_DEFAULT_KW);

if (pm_locals_reads(&parser->current_scope->locals, name_id) != reads) {
if (parser->version == PM_OPTIONS_VERSION_CRUBY_3_3 && (pm_locals_reads(&parser->current_scope->locals, name_id) != reads)) {
PM_PARSER_ERR_TOKEN_FORMAT_CONTENT(parser, local, PM_ERR_PARAMETER_CIRCULAR);
}

Expand Down
22 changes: 14 additions & 8 deletions test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1990,12 +1990,18 @@ def foo(bar: bar) = 42
proc { |foo: foo| }
RUBY

assert_errors expression(source), source, [
["circular argument reference - bar", 8..11],
["circular argument reference - bar", 32..35],
["circular argument reference - foo", 55..58],
["circular argument reference - foo", 76..79]
]
assert_errors(
expression(source),
source,
[
["circular argument reference - bar", 8..11],
["circular argument reference - bar", 32..35],
["circular argument reference - foo", 55..58],
["circular argument reference - foo", 76..79]
],
check_valid_syntax: false,
version: "3.3.0"
)

refute_error_messages("def foo(bar: bar = 1); end")
end
Expand Down Expand Up @@ -2244,10 +2250,10 @@ def test_unexpected_block

private

def assert_errors(expected, source, errors, check_valid_syntax: true)
def assert_errors(expected, source, errors, check_valid_syntax: true, **options)
refute_valid_syntax(source) if check_valid_syntax

result = Prism.parse(source)
result = Prism.parse(source, **options)
node = result.value.statements.body.last

assert_equal_nodes(expected, node, compare_location: false)
Expand Down

0 comments on commit 8b54e16

Please sign in to comment.