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

checker: abstract repetitive error handling #18507

Merged
merged 3 commits into from
Jun 21, 2023

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Jun 21, 2023

🤖 Generated by Copilot at 569b52a

This pull request refactors and simplifies the error reporting and checking logic for various expressions involving stack objects, or blocks, ? and ! operators in the V compiler. It extracts two common functions expr_or_block_err and fail_if_stack_struct_action_outside_unsafe in vlib/v/checker/checker.v and reuses them in other modules. It also updates the error messages and the corresponding tests to be more specific and consistent.

🤖 Generated by Copilot at 569b52a

  • Extract common logic for checking if an identifier refers to a stack object that cannot be assigned outside unsafe blocks to a new function fail_if_stack_sturct_action_outside_unsafe in vlib/v/checker/checker.v (link, link)
  • Use the new function fail_if_stack_sturct_action_outside_unsafe to simplify the code in vlib/v/checker/assign.v, vlib/v/checker/return.v, and vlib/v/checker/struct.v (link, link)
  • Add a new function expr_or_block_err in vlib/v/checker/checker.v that handles the error reporting for unexpected or blocks, ? and ! operators when the expression is not an Option or a Result (link)
  • Use the new function expr_or_block_err to simplify the code and improve the error messages in vlib/v/checker/checker.v for function call expressions, selector expressions, go statements, and struct init expressions (link, link, link, link)
  • Update the expected output of the tests in vlib/v/checker/tests/go_wait_or.out, vlib/v/checker/tests/struct_field_option_err.out, and vlib/v/checker/tests/unexpected_or_propagate.out to match the new error messages generated by the new function expr_or_block_err (link, link, link, link)

@@ -19,7 +19,7 @@ vlib/v/checker/tests/go_wait_or.vv:19:13: error: unexpected `or` block, the func
| ~~~~~~~~~~~~~~~~~~~~~~~
20 | tg2[0].wait()?
21 | tg3 := [
vlib/v/checker/tests/go_wait_or.vv:20:15: error: unexpected `?`, the function `wait` does not return an Option or a Result
Copy link
Member Author

@ttytm ttytm Jun 21, 2023

Choose a reason for hiding this comment

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

The error handlers already had explicitly checked if we .propagate_option or .propagate_result.

I assume we therefore don't need the or a Result. Other errors already have taken that into account and ended with just an Option. It was just this error that went out of the line.

@@ -26,7 +26,7 @@ vlib/v/checker/tests/struct_field_option_err.vv:16:19: error: last statement in
| ^
17 |
18 | _ = f.baz?
vlib/v/checker/tests/struct_field_option_err.vv:18:11: error: unexpected `?`, the field `baz` is neither an Option, nor a Result
Copy link
Member Author

Choose a reason for hiding this comment

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

Due to the abstraction this was adapted to be uniform with the predominantly used phrasing is not ...

Co-authored-by: JalonSolov <37967083+jalonsolov@users.noreply.github.com>
@JalonSolov
Copy link
Contributor

The or a Result phrasing is likely left over from when ? meant both.

As long as the error matches the type... is not an Option or is not a Result.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Good work.

@spytheman spytheman merged commit 867f437 into vlang:master Jun 21, 2023
@ttytm ttytm deleted the checker/abstract-repetitive-error-fns branch August 22, 2023 13:34
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.

3 participants