Repository navigation
cl: support range over integer types (Go 1.22+) - #2714
Conversation
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>
There was a problem hiding this comment.
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)
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
No description provided.