vendor: type asserting vendored code VS $GOPATH code yield awkward experience #18706
Labels
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What version of Go are you using (
go version
)?go version go1.7.4 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/brenol/goworkspace"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build237439903=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
What did you do?
A type assertion from a type inside another package that is actually vendored in that other package.
Given the following directory structure:
formatter/format.go:
parser/parser.go
parser/vendor/github.com/brenol/formatter/format.go:
use_parser_and_formatter/main.go:
What did you expect to see?
I do not expect it to be of the same type - because they actually aren't - one is parser/vendor/github.com/brenol/formatter.Format and the another one is github.com/brenol/formatter/Format.
The behavior is correct, as expected. The problem is that this is cumbersome to track down and is very easy to miss. Perhaps %T should also show the package for that type, or the compiler should be more aggressive when checking for type assertions? I am not sure on how to improve the user experience on this one.
What did you see instead?
The text was updated successfully, but these errors were encountered: