Skip to content

cl: support range over integer types (Go 1.22+) - #2714

Merged
xushiwei merged 4 commits into
goplus:mainfrom
xushiwei:i2703
Apr 12, 2026
Merged

xushiwei merged 4 commits into
goplus:mainfrom
xushiwei:i2703

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

xgopilot and others added 3 commits April 12, 2026 01:08
Update gogen dependency to support `for i := range n` where n is an
integer, iterating from 0 to n-1. Add tests for both the _testgop
directory and inline compile tests.

Closes goplus#2703

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

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review Summary

Clean, well-scoped Phase 2 PR that adds range-over-integer support (Go 1.22+) by bumping the gogen dependency and adding tests. No performance or security concerns. One suggestion on test coverage below.

Comment thread cl/_testgop/for-range-int/in.xgo

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 support for range-over-integer syntax by updating the gogen dependency and adding corresponding test cases. The review feedback recommends expanding the test suite to include non-constant integer expressions and various integer types to ensure comprehensive coverage of the feature.

I am having trouble creating individual review comments. Click here to see my feedback.

cl/compile_test.go (2081-2102)

medium

The test coverage for the new range-over-integer feature is currently limited to constant integers. It would be beneficial to add test cases for non-constant integer expressions (e.g., for i := range n) and different integer types (e.g., uint32, int16) to ensure the compiler correctly handles these scenarios as supported by Go 1.22+.

func TestRangeStmtInt(t *testing.T) {
	gopClTest(t, `
for i := range 10 {
	println(i)
}
for range 5 {
	println("Hi")
}
n := 3
for i := range n {
	println(i)
}
for i := range uint32(2) {
	println(i)
}
`, `package main

import "fmt"

func main() {
	for i := range 10 {
		fmt.Println(i)
	}
	for range 5 {
		fmt.Println("Hi")
	}
	n := 3
	for i := range n {
		fmt.Println(i)
	}
	for i := range uint32(2) {
		fmt.Println(i)
	}
}
`)
}

@codecov

codecov Bot commented Apr 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.12%. Comparing base (799f9a9) to head (43e6e50).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2714   +/-   ##
=======================================
  Coverage   94.12%   94.12%           
=======================================
  Files          32       32           
  Lines       10054    10054           
=======================================
  Hits         9463     9463           
  Misses        421      421           
  Partials      170      170           

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xushiwei
xushiwei merged commit 629068a into goplus:main Apr 12, 2026
11 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.

2 participants