Skip to content

Commit cd5eb8c

Browse files
maratorickaznocha
authored andcommitted
Fix panic
Closes #16
1 parent 8da82a3 commit cd5eb8c

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

intrange.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,11 @@ func check(pass *analysis.Pass) func(node ast.Node) {
234234
func findNExpr(expr ast.Expr) ast.Expr {
235235
switch e := expr.(type) {
236236
case *ast.CallExpr:
237-
if e.Fun.(*ast.Ident).Name != "len" {
238-
return nil
237+
if fun, ok := e.Fun.(*ast.Ident); ok && fun.Name == "len" && len(e.Args) == 1 {
238+
return findNExpr(e.Args[0])
239239
}
240240

241-
if len(e.Args) != 1 {
242-
return nil
243-
}
244-
245-
return findNExpr(e.Args[0])
241+
return nil
246242
case *ast.BasicLit:
247243
return nil
248244
case *ast.Ident:

testdata/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/ckaznocha/intrange/testdata
22

33
go 1.21
4+
5+
require google.golang.org/protobuf v1.33.0

testdata/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
2+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=

testdata/main.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package main
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
"google.golang.org/protobuf/reflect/protoreflect"
7+
)
48

59
func main() {
610
for i := 2; i < 10; i++ {
@@ -187,3 +191,10 @@ func main() {
187191
t2.m[4] = 4
188192
}
189193
}
194+
195+
// https://github.com/ckaznocha/intrange/issues/16
196+
func issue16(service protoreflect.ServiceDescriptor) {
197+
for i := 0; i < service.Methods().Len(); i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
198+
print(i)
199+
}
200+
}

0 commit comments

Comments
 (0)