8000 Error recovery for case by jez · Pull Request #5277 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Error recovery for case #5277

< 8000 div class="gh-header-actions mt-0 mb-3 mb-md-2 ml-1 flex-md-order-1 flex-shrink-0 d-flex flex-items-center gap-1">
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

Merged
merged 3 commits into from
Feb 10, 2022
Merged

Error recovery for case #5277

merged 3 commits into from
Feb 10, 2022

Conversation

jez
Copy link
Collaborator
@jez jez commented Feb 9, 2022

Motivation

Sorry, I didn't go through the work of making this one into small commits.

Test plan

See included automated tests.

@jez jez requested a review from a team as a code owner February 9, 2022 08:37
@jez jez requested review from froydnj and removed request for a team February 9, 2022 08:37
@jez jez force-pushed the jez-case branch 2 times, most recently from 10b796b to b7bc0f3 Compare February 9, 2022 08:43
Copy link
Contributor
@froydnj froydnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is reasonable, but I have concerns about:

  1. rewind_if_dedented now appearing in rules that aren't actually errors, which seems like scope creep.
  2. various things that don't seem to be used or changes that appear spurious.

Will stamp once those concerns are cleared up.

{
auto &case_body = $4;
auto &else_ = case_body->els;
$$ = driver.build.case_match(self, $1, $2,
&case_body->whens,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, $5);
driver.rewind_if_dedented($1, $5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me why we need to alter the behavior of the pattern-matching case here, since this was existing non-error code. Shouldn't this be removed?

}
| kCASE expr_value opt_terms p_case_body kEND
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was the only production in this file that didn’t have its pipe character aligned so I fixed it.

@@ -1856,6 +1856,7 @@ lbrace_cmd_block_start:
&case_body->whens,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, $5);
driver.rewind_if_dedented($1, $5);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we rewinding in existing productions?

@@ -1865,15 +1866,40 @@ lbrace_cmd_block_start:
&case_body->whens,
else_ ? else_->tok : nullptr,
else_ ? else_->nod : nullptr, $4);
driver.rewind_if_dedented($1, $4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we rewinding in existing productions?

@jez
Copy link
Collaborator Author
jez commented Feb 9, 2022

I've fixed the small changes. Thanks for pointing those out.

To answer all the "Why are we rewinding in existing productions?" questions:

That is the whole point of the change. Calling rewind_if_dedented in those cases:

  • will only do anything if driver.indentationAware is set, which is only set when we're doing a second parse to attempt better error recovery
  • is crucial to make every test that I added in this PR pass—none of them pass without this change. Every production rule that I've modified in this PR has at least one, but usually many more, tests.

@jez jez requested a review from froydnj February 9, 2022 18:16
@froydnj froydnj assigned jez and unassigned froydnj Feb 9, 2022
@jez
Copy link
Collaborator Author
jez commented Feb 9, 2022

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_L7diw9SiuA6mWC
https://go/builds/bui_L7di9yer8NQ7mG

@jez jez force-pushed the jez-do-end branch 2 times, most recently from 6c5e833 to ae88a6d Compare February 10, 2022 18:45
Base automatically changed from jez-do-end to master February 10, 2022 19:33
@jez jez merged commit d513258 into master Feb 10, 2022
@jez jez deleted the jez-case branch February 10, 2022 19:58
@jez jez added this to the Better Parser milestone Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0