Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/vet: check unkeyed fields only when pkg is built #16725

Closed
ymmt2005 opened this issue Aug 16, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@ymmt2005
Copy link

commented Aug 16, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version go1.7 linux/amd64

  1. What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ymmt/t"
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-build329948438=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

  1. What did you do?
  • Create a.go and b.go as follows:
cd $GOPATH
mkdir -p src/a src/b
cat >src/a/a.go <<EOF
package a

type A struct {
    Key string
}
EOF
cat >src/b/b.go <<EOF
package b

import "a"

var B = []a.A{
    {"abc"},
}
EOF
  • Run go vet without built binaries will not produce warnings.
cd $GOPATH
rm -rf pkg
go vet a b
  • After built a, go vet produce warnings.
cd $GOPATH
go install a
go vet a b
  1. What did you expect to see?

    src/b/b.go:6: a.A composite literal uses unkeyed fields
    exit status 1

  2. What did you see instead?

Nothing, if no a binary.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2016

Unfortunate, known, and maybe working as intended. Vet can't type check if the packages being imported have not been compiled, as there is no type information for them.

@robpike robpike closed this Aug 16, 2016

@ymmt2005

This comment has been minimized.

Copy link
Author

commented Aug 16, 2016

@robpike Thank you.

If this is intended, I'd like to suggest improving cmd/vet documentation
so that users can compile packages in advance.

Currently, there's no compilation information:
https://golang.org/cmd/vet/

ymmt2005 added a commit to cybozu-go/aptutil that referenced this issue Aug 16, 2016

@Liamsi Liamsi referenced this issue Aug 26, 2016

Closed

Switch to go 1.7 #558

@golang golang locked and limited conversation to collaborators Aug 16, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.