Skip to content

Commit

Permalink
Use method sets to check members instead
Browse files Browse the repository at this point in the history
  • Loading branch information
winston-stripe committed Dec 13, 2023
1 parent 45428c5 commit be192f8
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions passes/errunwrap/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ func isErrorType(t types.Type) bool {

// unwrapMethod checks if the type has an Unwrap method
func unwrapMethod(t types.Type) (*types.Func, bool) {
// Check if the type is a named type
named, ok := t.(*types.Named)
if !ok {
return nil, false
}
// We always get a concrete type here, however we want to check the pointer receiver as well
methods := types.NewMethodSet(types.NewPointer(t))

for i := 0; i < named.NumMethods(); i++ {
method := named.Method(i)
for i := 0; i < methods.Len(); i++ {
method := methods.At(i).Obj().(*types.Func)

// Check if the method is the Unwrap method
if method.Name() == "Unwrap" {
Expand Down

0 comments on commit be192f8

Please sign in to comment.