Skip to content

Commit 9a54195

Browse files
ldezchavacava
andauthored
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 <[email protected]>
1 parent 3e3e982 commit 9a54195

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

internal/astutils/ast_utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package astutils
33

44
import (
5-
"fmt"
65
"go/ast"
76
)
87

@@ -73,7 +72,11 @@ func getFieldTypeName(typ ast.Expr) string {
7372
return "*" + getFieldTypeName(f.X)
7473
case *ast.IndexExpr:
7574
return getFieldTypeName(f.X) + "[" + getFieldTypeName(f.Index) + "]"
75+
case *ast.ArrayType:
76+
return "[]" + getFieldTypeName(f.Elt)
77+
case *ast.InterfaceType:
78+
return "interface{}"
7679
default:
77-
panic(fmt.Sprintf("not supported type %T", typ))
80+
return "UNHANDLED_TYPE"
7881
}
7982
}

testdata/golint/sort.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,12 @@ func (x X) Less(i *pkg.tip) (result bool) { return len(x) } // MATCH /exported m
4444

4545
// Test for issue #1217
4646
func (s *synchronized[T]) Swap(other Synchronized[T]) {}
47+
48+
// Swap for issue #1228
49+
func (s *synchronized[T]) Swap(other interface{}) {}
50+
51+
// Swap for issue #1228
52+
func (s *synchronized[T]) Swap(other []int) {}
53+
54+
// Swap for issue #1228
55+
func (s *synchronized[T]) Swap(other []interface{}) {}

0 commit comments

Comments
 (0)