Closed
Description
What version of Go are you using (go version
)?
$ go version go1.17.6 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/Users/xxxxx/Library/Caches/go-build" GOENV="/Users/xxxxx/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/xxxxx/go/pkg/mod" GONOPROXY="xxxxxxxx" GONOSUMDB="xxxxxxxx" GOOS="darwin" GOPATH="/Users/xxxxx/go" GOPRIVATE="xxxxxxxx" GOPROXY="xxxxxxxxx" GOROOT="/usr/local/Cellar/go/1.17.6/libexec" GOSUMDB="sum.golang.google.cn" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.17.6/libexec/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.17.6" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p0/kb961x5d6wd79gfp2h6t_8500000gn/T/go-build1578457773=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
I have written a simple program. It contains variables that are defined but not used. It can be successfully compiled to executable program, but when I load the package with golang analysis tool, I get the error that it is defined but not used.
package main
import (
"fmt"
"golang.org/x/tools/go/packages"
)
func main() {
rootDir := "/tmp/example"
cfg := &packages.Config{
Mode: packages.LoadAllSyntax,
Tests: false,
Dir: rootDir,
}
packageArr, _ := packages.Load(cfg)
fmt.Printf("pkg err : %+v", packageArr[0].Errors)
}
err output
pkg err : [/tmp/example/main.go:11:4: vv declared but not used]
What did you expect to see?
I would like to see a consistent behavior of the compilation tools, either fail or both succeed.
What did you see instead?
inconsistent results
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
seankhliao commentedon Apr 14, 2022
Duplicate of #3059