Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing local_vars test by translating post params #386

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion parser/prism/Translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1027,21 +1027,24 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node) {
auto requireds = absl::MakeSpan(paramsNode->requireds.nodes, paramsNode->requireds.size);
auto optionals = absl::MakeSpan(paramsNode->optionals.nodes, paramsNode->optionals.size);
auto keywords = absl::MakeSpan(paramsNode->keywords.nodes, paramsNode->keywords.size);
auto posts = absl::MakeSpan(paramsNode->posts.nodes, paramsNode->posts.size);

parser::NodeVec params;

auto restSize = paramsNode->rest == nullptr ? 0 : 1;
auto kwrestSize = paramsNode->keyword_rest == nullptr ? 0 : 1;
auto blockSize = paramsNode->block == nullptr ? 0 : 1;

params.reserve(requireds.size() + optionals.size() + restSize + keywords.size() + kwrestSize + blockSize);
params.reserve(requireds.size() + optionals.size() + restSize + posts.size() + keywords.size() +
kwrestSize + blockSize);

translateMultiInto(params, requireds);
translateMultiInto(params, optionals);

if (paramsNode->rest != nullptr)
params.emplace_back(translate(paramsNode->rest));

translateMultiInto(params, posts);
translateMultiInto(params, keywords);

if (auto prismKwRestNode = paramsNode->keyword_rest; prismKwRestNode != nullptr) {
Expand Down
4 changes: 1 addition & 3 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ pipeline_tests(
"testdata/parser/invalid_fatal.rb",
"testdata/parser/invalid_syntax_error.rb",
"testdata/parser/kwargs_missing_comma.rb",
"testdata/parser/kwnil_errors.rb", # See https://github.com/Shopify/sorbet/issues/393
"testdata/parser/misc.rb",
"testdata/parser/offset0.rb",
"testdata/parser/ruby_25.rb",
Expand All @@ -292,9 +293,6 @@ pipeline_tests(
"testdata/rewriter/prop.rb",
"testdata/rewriter/struct.rb",

# Failing local_vars tests to investigate
"testdata/local_vars/z_super_args_splats_blocks.rb",

# Sorbets' parser incorrectly accepts invalid syntax
"testdata/desugar/pattern_matching_hash.rb", # See https://github.com/Shopify/sorbet/issues/362
],
Expand Down
17 changes: 17 additions & 0 deletions test/prism_regression/def_rest_params.parse-tree.exp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,22 @@ Begin {
}
body = NULL
}
DefMethod {
name = <U foo>
args = Args {
args = [
Restarg {
name = <U a>
}
Arg {
name = <U b>
}
Arg {
name = <U c>
}
]
}
body = NULL
}
]
}
3 changes: 3 additions & 0 deletions test/prism_regression/def_rest_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
def foo(*a); end

def foo(*); end

# Rest with posts
def foo(*a, b, c); end
Loading