Skip to content

fix: panic with getFieldTypeName #1229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{}) {}