Skip to content

Conversation

@aofei
Copy link
Member

@aofei aofei commented Dec 12, 2025

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

Copilot AI review requested due to automatic review settings December 12, 2025 03:29
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Missing Return Detection: Implemented a new static analysis check to detect functions that are declared to return values but do not properly terminate with a return statement across all execution paths.
  • Early Error Reporting: This new detection mechanism allows 'missing return' errors to be reported during code generation, preventing potential runtime issues and improving code quality.
  • Go Standard Library Adaptation: The core logic for determining statement termination (isTerminating) is adapted from the go/types/return.go package in the Go standard library, ensuring robust and accurate analysis.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.00%. Comparing base (d8e0fc9) to head (da2476a).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link

Copilot AI left a 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.go file implementing terminating statement detection logic
  • Integration of the check into func.go to 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.

@aofei aofei force-pushed the missing-return branch 2 times, most recently from 2938d96 to 94cde8f Compare December 12, 2025 05:26
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]>
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 12, 2025
- 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]>
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 12, 2025
- 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]>
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 12, 2025
- 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]>
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 12, 2025
- 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]>
@xushiwei xushiwei merged commit 03c926d into goplus:main Dec 13, 2025
23 checks passed
@aofei aofei deleted the missing-return branch December 13, 2025 03:19
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 15, 2025
- 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]>
aofei added a commit to aofei/fork.goplus.xgolsw that referenced this pull request Dec 15, 2025
- 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]>
aofei added a commit to goplus/xgolsw that referenced this pull request Dec 15, 2025
- 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]>
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