From d0d7a3203b19835c7eecab3a24598c3664380663 Mon Sep 17 00:00:00 2001 From: joaks Date: Mon, 1 Jul 2024 20:22:29 +0000 Subject: [PATCH] use build tags --- errcheck/embedded_walker.go | 4 ++-- errcheck/embedded_walker_121.go | 10 ++++++++++ errcheck/embedded_walker_122.go | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 errcheck/embedded_walker_121.go create mode 100644 errcheck/embedded_walker_122.go diff --git a/errcheck/embedded_walker.go b/errcheck/embedded_walker.go index ab5c17a..98f28e9 100644 --- a/errcheck/embedded_walker.go +++ b/errcheck/embedded_walker.go @@ -84,8 +84,8 @@ func walkThroughEmbeddedInterfaces(sel *types.Selection) ([]types.Type, bool) { } func getTypeAtFieldIndex(startingAt types.Type, fieldIndex int) types.Type { - t := maybeDereference(types.Unalias(startingAt)) - t = maybeUnname(types.Unalias(t)) + t := maybeDereference(maybeUnalias(startingAt)) + t = maybeUnname(maybeUnalias(t)) s, ok := t.(*types.Struct) if !ok { panic(fmt.Sprintf("cannot get Field of a type that is not a struct, got a %T", t)) diff --git a/errcheck/embedded_walker_121.go b/errcheck/embedded_walker_121.go new file mode 100644 index 0000000..f2df684 --- /dev/null +++ b/errcheck/embedded_walker_121.go @@ -0,0 +1,10 @@ +//go:build !go1.22 +// +build !go1.22 + +package errcheck + +import "go/types" + +func maybeUnalias(t types.Type) types.Type { + return t +} diff --git a/errcheck/embedded_walker_122.go b/errcheck/embedded_walker_122.go new file mode 100644 index 0000000..cbff3cd --- /dev/null +++ b/errcheck/embedded_walker_122.go @@ -0,0 +1,10 @@ +//go:build go1.22 +// +build go1.22 + +package errcheck + +import "go/types" + +func maybeUnalias(t types.Type) types.Type { + return types.Unalias(t) +}