Skip to content

Commit

Permalink
Correctly translate constant write nodes' location
Browse files Browse the repository at this point in the history
This is not covered in parse tree location tests, but reflected in symbol
table tests: when we write `FOO = 1` (or other constant write nodes), the
location of `FOO` should just be the name, not the entire assignment.

In those cases, we should use `name_loc` instead of `base.location`.
  • Loading branch information
st0012 committed Jan 6, 2025
1 parent 29be814 commit 237ed5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
8 changes: 8 additions & 0 deletions parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,14 @@ unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool rep
is_same_v<PrismLhsNode, pm_constant_operator_write_node> ||
is_same_v<PrismLhsNode, pm_constant_target_node> || is_same_v<PrismLhsNode, pm_constant_read_node> ||
is_same_v<PrismLhsNode, pm_constant_write_node>);

// For writes, location should only include the name, like `FOO` in `FOO = 1`.
if constexpr (is_same_v<PrismLhsNode, pm_constant_and_write_node> ||
is_same_v<PrismLhsNode, pm_constant_or_write_node> ||
is_same_v<PrismLhsNode, pm_constant_operator_write_node> ||
is_same_v<PrismLhsNode, pm_constant_write_node>) {
location = translateLoc(node->name_loc);
}
parent = nullptr;
}

Expand Down
11 changes: 0 additions & 11 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ pipeline_tests(
"testdata/lsp/completion/self_receiver.rb",

# Desugar tests having to do with tree differences; will address later
"testdata/desugar/constant_error.rb",
"testdata/desugar/for.rb",
"testdata/desugar/sclass.rb",

# Rewriter tests having to do with symbol table differences; will address later
Expand All @@ -306,17 +304,8 @@ pipeline_tests(
"testdata/rewriter/struct.rb",

# Failing namer tests to investigate
"testdata/namer/alias_cross_file__01.rb",
"testdata/namer/alias_cross_file__02.rb",
"testdata/namer/all_constant_redefinitions.rb",
"testdata/namer/class_alias_inside_method.rb",
"testdata/namer/class_and_alias.rb",
"testdata/namer/constant_in_block.rb",
"testdata/namer/constant_types.rb",
"testdata/namer/constants.rb",
"testdata/namer/fuzz_class_in_field.rb",
"testdata/namer/fuzz_repeated_kwarg.rb",
"testdata/namer/fuzz_type_template_overwrite.rb",
"testdata/namer/module_function.rb",
"testdata/namer/parameter_names.rb",
"testdata/namer/redefinition_method.rb",
Expand Down

0 comments on commit 237ed5c

Please sign in to comment.