From 2833b2f37abf04e859cb2a8d319a0805b21eb9a0 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 7 Jan 2025 14:33:44 +0000 Subject: [PATCH 1/2] Fix symbol location for hash, keyword argument keys When the symbol is used as `a: 1`, the location should not include the colon. --- parser/prism/Translator.cc | 8 +++++++- test/BUILD | 19 ------------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/parser/prism/Translator.cc b/parser/prism/Translator.cc index a7069b74b2d..18a0c73280a 100644 --- a/parser/prism/Translator.cc +++ b/parser/prism/Translator.cc @@ -1261,13 +1261,19 @@ unique_ptr Translator::translate(pm_node_t *node) { returnValues = translateArguments(superNode->arguments, blockArgumentNode); return make_unique(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(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(location, gs.enterNameUTF8(source)); } diff --git a/test/BUILD b/test/BUILD index 09c04022827..299714e9212 100644 --- a/test/BUILD +++ b/test/BUILD @@ -293,26 +293,7 @@ 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", # Sorbets' parser incorrectly accepts invalid syntax "testdata/desugar/pattern_matching_hash.rb", # See https://github.com/Shopify/sorbet/issues/362 From 3f8bf0f8b0145bfe135c5ec175b9bce02e2e63f3 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Tue, 7 Jan 2025 15:53:51 +0000 Subject: [PATCH 2/2] Run Prism Corpus against all Sorbet component tests --- test/BUILD | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/test/BUILD b/test/BUILD index 299714e9212..edfdcf4eec5 100644 --- a/test/BUILD +++ b/test/BUILD @@ -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 @@ -294,6 +284,7 @@ pipeline_tests( "testdata/lsp/completion/missing_fun.rb", "testdata/lsp/completion/self_receiver.rb", "testdata/namer/fuzz_repeated_kwarg.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