Skip to content

Commit

Permalink
Fix panic
Browse files Browse the repository at this point in the history
Closes #16
  • Loading branch information
maratori authored and ckaznocha committed Mar 26, 2024
1 parent 8da82a3 commit cd5eb8c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
10 changes: 3 additions & 7 deletions intrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,11 @@ func check(pass *analysis.Pass) func(node ast.Node) {
func findNExpr(expr ast.Expr) ast.Expr {
switch e := expr.(type) {
case *ast.CallExpr:
if e.Fun.(*ast.Ident).Name != "len" {
return nil
if fun, ok := e.Fun.(*ast.Ident); ok && fun.Name == "len" && len(e.Args) == 1 {
return findNExpr(e.Args[0])
}

if len(e.Args) != 1 {
return nil
}

return findNExpr(e.Args[0])
return nil
case *ast.BasicLit:
return nil
case *ast.Ident:
Expand Down
2 changes: 2 additions & 0 deletions testdata/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/ckaznocha/intrange/testdata

go 1.21

require google.golang.org/protobuf v1.33.0
2 changes: 2 additions & 0 deletions testdata/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
13 changes: 12 additions & 1 deletion testdata/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import "testing"
import (
"testing"

"google.golang.org/protobuf/reflect/protoreflect"
)

func main() {
for i := 2; i < 10; i++ {
Expand Down Expand Up @@ -187,3 +191,10 @@ func main() {
t2.m[4] = 4
}
}

// https://github.com/ckaznocha/intrange/issues/16
func issue16(service protoreflect.ServiceDescriptor) {
for i := 0; i < service.Methods().Len(); i++ { // want `for loop can be changed to use an integer range \(Go 1\.22\+\)`
print(i)
}
}

0 comments on commit cd5eb8c

Please sign in to comment.