From 9a5419522817cccf323b39798ccf6d202b518943 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Wed, 12 Feb 2025 14:10:48 +0100 Subject: [PATCH] fix: panic with getFieldTypeName (#1229) * fix: panic with interface type and array * replaces panic with a return of a default string * review --------- Co-authored-by: chavacava --- internal/astutils/ast_utils.go | 7 +++++-- testdata/golint/sort.go | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/astutils/ast_utils.go b/internal/astutils/ast_utils.go index bcd13d8d1..0a346043a 100644 --- a/internal/astutils/ast_utils.go +++ b/internal/astutils/ast_utils.go @@ -2,7 +2,6 @@ package astutils import ( - "fmt" "go/ast" ) @@ -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" } } diff --git a/testdata/golint/sort.go b/testdata/golint/sort.go index e4e5c985f..e82057a3e 100644 --- a/testdata/golint/sort.go +++ b/testdata/golint/sort.go @@ -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{}) {}