-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add missing return detection for funcs with return values #550
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
Conversation
Summary of ChangesHello @aofei, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant improvement to the code generation process by adding static analysis for missing return statements in functions that are expected to return values. By integrating a termination check based on the Go standard library's approach, the system can now identify and report these errors at compile-time rather than allowing them to manifest as runtime failures, thereby enhancing the reliability and correctness of generated code. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #550 +/- ##
=======================================
Coverage 95.99% 96.00%
=======================================
Files 23 23
Lines 6474 6482 +8
=======================================
+ Hits 6215 6223 +8
Misses 193 193
Partials 66 66 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a 'missing return' detection mechanism for functions with return values, which is a great feature to catch errors at code generation time. The implementation is based on the Go standard library's return analysis, which is a solid approach. The changes include the core logic in func.go, the termination analysis in a new return.go file, and updates to existing tests to accommodate the new checks, plus new tests for the feature itself.
My review identified a critical correctness issue in the isTerminating logic for select statements in return.go. I've also suggested a refactoring for one of the new test functions in error_msg_test.go to improve its maintainability. Apart from these points, the changes look good and the tests are comprehensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds missing return detection for functions with return values by implementing an isTerminating check based on go/types/return.go from the Go standard library. This enhancement enables the detection of functions that have return values but do not properly terminate, allowing "missing return" errors to be reported during code generation rather than at runtime.
Key changes:
- New
return.gofile implementing terminating statement detection logic - Integration of the check into
func.goto validate functions before code generation - Updated existing tests to add proper return statements to previously incomplete function bodies
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| return.go | New file implementing isTerminating and supporting functions to detect whether statements properly terminate control flow (returns, panics, infinite loops, etc.) |
| func.go | Integrates the missing return check in the End() method to validate functions with return values properly terminate before code generation |
| package_test.go | Adds return statements to test functions that now require them due to the new validation |
| error_msg_test.go | Adds comprehensive test coverage for missing return detection, including error cases and valid scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2938d96 to
94cde8f
Compare
Add `isTerminating` check (based on go/types/return.go from Go stdlib) to detect funcs that have return values but do not terminate properly. This enables reporting "missing return" errors during code generation rather than at runtime. Updates goplus/builder#2576 Signed-off-by: Aofei Sheng <[email protected]>
94cde8f to
da2476a
Compare
- Update gogen to include missing return detection for funcs with return values[^]1, enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Update gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Update gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Update gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Bump gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Bump gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
- Bump gogen to include missing return detection for funcs with return values[^1], enabling "missing return" errors to be reported in the editor rather than only at runtime - Use `RangeForPosEnd` instead of `RangeForPos` to properly report both start and end positions from `gogen.CodeError` - Use `codeError.Msg` instead of `codeError.Error` to avoid duplicate position info in message - Add `MissingReturn` test case for diagnostic detection - Skip empty diagnosticss in `inspectDiagnosticsAnalyzers` Fixes goplus/builder#2576 [^1]: goplus/gogen#550 Signed-off-by: Aofei Sheng <[email protected]>
Add
isTerminatingcheck (based on go/types/return.go from Go stdlib) to detect funcs that have return values but do not terminate properly. This enables reporting "missing return" errors during code generation rather than at runtime.Updates goplus/builder#2576