BurntSushi / go-sumtype

A simple utility for running exhaustiveness checks on Go "sum types."

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update to support Go 1.11 modules

atombender opened this issue · comments

go-sumtype seems to fail with "could not import" errors, even (surprisingly) after go mod vendor. From what I can tell, it needs to be updated to understand Go modules.

Can you provide a reproducible example on which to run?

@BurntSushi Here. There's something weird going on. If I use a GOPATH that's somewhere outside the working directory, it fails:

$ GOPATH=$HOME/.go ./run.sh
+ export GO111MODULE=on
+ GO111MODULE=on
+ go mod download
+ go build -o st .
+ go-sumtype .
/Users/alex/.go/pkg/mod/golang.org/x/sync@v0.0.0-20180314180146-1d60e4601c6f/semaphore/semaphore.go:15:2: could not import golang.org/x/net/context (cannot find package "golang.org/x/net/context" in any of:
	/usr/local/opt/go/libexec/src/golang.org/x/net/context (from $GOROOT)
	/Users/alex/.go/src/golang.org/x/net/context (from $GOPATH))
couldn't load packages due to errors: golang.org/x/sync/semaphore

But if I put the GOPATH under the current directory, there are no issues.

$ GOPATH=$PWD/.go ./run.sh
+ export GO111MODULE=on
+ GO111MODULE=on
+ go mod download
+ go build -o st .
+ go-sumtype .

The problem appears to be with transitive dependencies. It can resolve the direct dependencies, but not the transitive ones. (Hence my test case uses golang.org/x/sync/semaphore, which imports golang.org/x/net/context.)

I've tried wiping my GOPATH.

$ go version
go version go1.11.1 darwin/amd64

I believe golang.org/x/tools/go/loader, which you use for loading Go code, has not been updated to support modules. Instead, there's a new package, golang.org/x/tools/go/packages. Discussion here. See this issue for an example of a different project struggling with the same issue.