Skip to content

Commit

Permalink
fix: panic with getFieldTypeName (#1229)
Browse files Browse the repository at this point in the history
* fix: panic with interface type and array

* replaces panic with a return of a default string

* review

---------

Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
  • Loading branch information
ldez and chavacava authored Feb 12, 2025
1 parent 3e3e982 commit 9a54195
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/astutils/ast_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package astutils

import (
"fmt"
"go/ast"
)

Expand Down Expand Up @@ -73,7 +72,11 @@ func getFieldTypeName(typ ast.Expr) string {
return "*" + getFieldTypeName(f.X)
case *ast.IndexExpr:
return getFieldTypeName(f.X) + "[" + getFieldTypeName(f.Index) + "]"
case *ast.ArrayType:
return "[]" + getFieldTypeName(f.Elt)
case *ast.InterfaceType:
return "interface{}"
default:
panic(fmt.Sprintf("not supported type %T", typ))
return "UNHANDLED_TYPE"
}
}
9 changes: 9 additions & 0 deletions testdata/golint/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ func (x X) Less(i *pkg.tip) (result bool) { return len(x) } // MATCH /exported m

// Test for issue #1217
func (s *synchronized[T]) Swap(other Synchronized[T]) {}

// Swap for issue #1228
func (s *synchronized[T]) Swap(other interface{}) {}

// Swap for issue #1228
func (s *synchronized[T]) Swap(other []int) {}

// Swap for issue #1228
func (s *synchronized[T]) Swap(other []interface{}) {}

0 comments on commit 9a54195

Please sign in to comment.