Skip to content

cl: support range over function types (Go 1.23) #587

Merged
xushiwei merged 5 commits intogoplus:mainfrom
xushiwei:rof
Feb 9, 2026
Merged

cl: support range over function types (Go 1.23) #587
xushiwei merged 5 commits intogoplus:mainfrom
xushiwei:rof

Conversation

@xushiwei
Copy link
Member

@xushiwei xushiwei commented Feb 9, 2026

No description provided.

xgopilot bot and others added 3 commits February 9, 2026 01:31
Add support for Go 1.23 iterator functions that can be used with
the range statement. This enables custom iterators with signatures:
- func(yield func() bool)           - 0 values
- func(yield func(V) bool)          - 1 value
- func(yield func(K, V) bool)       - 2 values

The checkIteratorFunc function detects these signatures and returns
appropriate key/value types for the range statement.

Fixes goplus/xgo#2607

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
Add three test cases for Go 1.23 iterator function support:
- TestForRangeFunc0: 0-value iterator (for range foo {})
- TestForRangeFunc1: 1-value iterator (for v := range bar {})
- TestForRangeFunc2: 2-value iterator (for k, v := range weekdays {})

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @xushiwei, 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 integrates support for the upcoming Go 1.23 feature that enables for range loops to iterate directly over function types. The changes involve updating the type checking mechanism for for range statements to correctly identify and validate iterator function signatures, ensuring they adhere to the new specification. Additionally, a suite of new tests has been added to verify the functionality across different iterator patterns, from functions yielding no values to those yielding key-value pairs.

Highlights

  • Go 1.23 Range Over Functions Support: Implements the new Go 1.23 feature allowing for range loops to iterate over function types, enhancing iteration capabilities.
  • Iterator Function Signature Validation: Introduces a new checkIteratorFunc to validate if a function signature conforms to the expected iterator pattern (e.g., func(yield func() bool), func(yield func(V) bool), func(yield func(K, V) bool)).
  • Extended for range Type Checking: Modifies the forRangeStmt.check method to include *types.Signature as a valid type for for range statements, delegating validation to checkIteratorFunc.
  • Comprehensive Testing: Adds new unit tests (Test_checkIteratorFunc, TestForRangeFunc0, TestForRangeFunc1, TestForRangeFunc2) to cover various scenarios of ranging over functions yielding 0, 1, or 2 values.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • builtin_test.go
    • Added reflect package import for deep equality checks in tests.
    • Introduced Test_checkIteratorFunc to thoroughly test the logic for identifying valid iterator function signatures.
    • Added newParams helper function to simplify the creation of types.Tuple for test cases.
  • package_test.go
    • Added TestForRangeFunc0 to verify for range behavior with iterator functions that yield zero values.
    • Added TestForRangeFunc1 to verify for range behavior with iterator functions that yield a single value.
    • Added TestForRangeFunc2 to verify for range behavior with iterator functions that yield two values (key-value pairs).
  • stmt.go
    • Modified the forRangeStmt.check method to include a new case *types.Signature, enabling the processing of function types in for range statements.
    • Implemented checkIteratorFunc to determine if a given *types.Signature is a valid Go 1.23 iterator function and to extract the types of the yielded values.
Activity
  • No human activity has been recorded for this pull request yet.
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 Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.07%. Comparing base (e9785e5) to head (db4a3b7).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #587      +/-   ##
==========================================
+ Coverage   96.06%   96.07%   +0.01%     
==========================================
  Files          25       25              
  Lines        6855     6879      +24     
==========================================
+ Hits         6585     6609      +24     
  Misses        202      202              
  Partials       68       68              

☔ 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 adds support for range over function types, a new feature in Go 1.23. The implementation correctly handles the new case *types.Signature in getKeyValTypes and adds a checkIteratorFunc to validate iterator function signatures. The accompanying tests in package_test.go are well-written and cover the new functionality. However, I've identified a few areas for improvement: the tests for checkIteratorFunc are missing positive cases, there's a misleading comment in checkIteratorFunc, and more importantly, the existing logic for handling for range variables doesn't seem to correctly validate against the number of values produced by function iterators, which could lead to a panic.

@xgopilot
Copy link
Contributor

xgopilot bot commented Feb 9, 2026

Code Review Summary

Great work implementing Go 1.23's range over function types! The implementation is clean and follows existing codebase patterns. Found three noteworthy issues:

  1. Documentation inaccuracy in checkIteratorFunc (line 629) - comment doesn't match implementation
  2. Missing type alias handling in checkIteratorFunc (line 639) - should use typesalias.Unalias() for consistency
  3. Test coverage gap - Test_checkIteratorFunc only tests negative cases; needs positive cases for valid iterator signatures

The integration tests are comprehensive, but the unit test should directly verify valid signatures return correct types.

@xushiwei xushiwei merged commit 7c92e31 into goplus:main Feb 9, 2026
21 checks passed
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.

1 participant