Skip to content

Commit

Permalink
Merge pull request #397 from Shopify/fix-#367
Browse files Browse the repository at this point in the history
Fix symbol location for hash, keyword argument keys
  • Loading branch information
st0012 authored Jan 7, 2025
2 parents 1c1fa84 + 3f8bf0f commit 86c3ab6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
8 changes: 7 additions & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1261,13 +1261,19 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
returnValues = translateArguments(superNode->arguments, blockArgumentNode);
return make_unique<parser::Super>(location, move(returnValues));
}
case PM_SYMBOL_NODE: { // A symbol literal, e.g. `:foo`
case PM_SYMBOL_NODE: { // A symbol literal, e.g. `:foo`, or `a:` in `{a: 1}`
auto symNode = down_cast<pm_symbol_node>(node);

auto unescaped = &symNode->unescaped;

auto source = parser.extractString(unescaped);

// If the opening location is null, the symbol is used as a key with a colon postfix, like `{a: 1}`
// In those cases, the location should not include the colon.
if (symNode->opening_loc.start == nullptr) {
location = translateLoc(symNode->value_loc);
}

// TODO: can these have different encodings?
return make_unique<parser::Symbol>(location, gs.enterNameUTF8(source));
}
Expand Down
34 changes: 3 additions & 31 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,8 @@ pipeline_tests(
[
# Replace [parser] with other phases to test Prism at that level
# Phases: https://github.com/Shopify/sorbet/blob/prism/docs/internals.md#phases
"testdata/parser/**/*.rb",
"testdata/parser/**/*.exp",
"testdata/desugar/**/*.rb",
"testdata/desugar/**/*.exp",
"testdata/rewriter/**/*.rb",
"testdata/rewriter/**/*.exp",
"testdata/local_vars/**/*.rb",
"testdata/local_vars/**/*.exp",
"testdata/namer/**/*.rb",
"testdata/namer/**/*.exp",
"testdata/lsp/**/*.rb",
"testdata/lsp/**/*.exp",
"testdata/**/*.rb",
"testdata/**/*.exp",
],
exclude = [
# Tests having to do with tree differences in invalid Ruby code; will address later
Expand All @@ -293,26 +283,8 @@ pipeline_tests(
"testdata/lsp/completion/missing_const_name.rb",
"testdata/lsp/completion/missing_fun.rb",
"testdata/lsp/completion/self_receiver.rb",

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

# Rewriter tests having to do with symbol table differences; will address later
"testdata/rewriter/attr_multi.rb",
"testdata/rewriter/attr.rb",
"testdata/rewriter/prop.rb",
"testdata/rewriter/struct.rb",

# Failing namer tests to investigate
"testdata/namer/class_alias_inside_method.rb",
"testdata/namer/fuzz_repeated_kwarg.rb",
"testdata/namer/module_function.rb",
"testdata/namer/parameter_names.rb",
"testdata/namer/redefinition_method.rb",
"testdata/namer/type_alias_inside_method.rb",
"testdata/namer/type_alias.rb",
"testdata/namer/type_member_inside_method.rb",
"testdata/namer/type_template_inside_method.rb",
"testdata/deviations/keyword_method_names.rb",

# Sorbets' parser incorrectly accepts invalid syntax
"testdata/desugar/pattern_matching_hash.rb", # See https://github.com/Shopify/sorbet/issues/362
Expand Down

0 comments on commit 86c3ab6

Please sign in to comment.