aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/alecthomas
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/alecthomas')
-rw-r--r--vendor/github.com/alecthomas/go-check-sumtype/decl.go1
-rw-r--r--vendor/github.com/alecthomas/go-check-sumtype/def.go16
2 files changed, 17 insertions, 0 deletions
diff --git a/vendor/github.com/alecthomas/go-check-sumtype/decl.go b/vendor/github.com/alecthomas/go-check-sumtype/decl.go
index ea2cd06df..9dec9eefd 100644
--- a/vendor/github.com/alecthomas/go-check-sumtype/decl.go
+++ b/vendor/github.com/alecthomas/go-check-sumtype/decl.go
@@ -57,6 +57,7 @@ func findSumTypeDecls(pkgs []*packages.Package) ([]sumTypeDecl, error) {
}
pos = pkg.Fset.Position(tspec.Pos())
decl := sumTypeDecl{Package: pkg, TypeName: tspec.Name.Name, Pos: pos}
+ debugf("found sum type decl: %s.%s", decl.Package.PkgPath, decl.TypeName)
decls = append(decls, decl)
break
}
diff --git a/vendor/github.com/alecthomas/go-check-sumtype/def.go b/vendor/github.com/alecthomas/go-check-sumtype/def.go
index 811b98f98..24729ac01 100644
--- a/vendor/github.com/alecthomas/go-check-sumtype/def.go
+++ b/vendor/github.com/alecthomas/go-check-sumtype/def.go
@@ -1,11 +1,21 @@
package gochecksumtype
import (
+ "flag"
"fmt"
"go/token"
"go/types"
+ "log"
)
+var debug = flag.Bool("debug", false, "enable debug logging")
+
+func debugf(format string, args ...interface{}) {
+ if *debug {
+ log.Printf(format, args...)
+ }
+}
+
// Error as returned by Run()
type Error interface {
error
@@ -107,6 +117,7 @@ func newSumTypeDef(pkg *types.Package, decl sumTypeDecl) (*sumTypeDef, error) {
Decl: decl,
Ty: iface,
}
+ debugf("searching for variants of %s.%s\n", pkg.Path(), decl.TypeName)
for _, name := range pkg.Scope().Names() {
obj, ok := pkg.Scope().Lookup(name).(*types.TypeName)
if !ok {
@@ -116,7 +127,12 @@ func newSumTypeDef(pkg *types.Package, decl sumTypeDecl) (*sumTypeDef, error) {
if types.Identical(ty.Underlying(), iface) {
continue
}
+ // Skip generic types.
+ if named, ok := ty.(*types.Named); ok && named.TypeParams() != nil {
+ continue
+ }
if types.Implements(ty, iface) || types.Implements(types.NewPointer(ty), iface) {
+ debugf(" found variant: %s.%s\n", pkg.Path(), obj.Name())
def.Variants = append(def.Variants, obj)
}
}