Skip to content

x/tools/go/packages:declared but not used #52345

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

Closed
lvyahui8 opened this issue Apr 14, 2022 · 1 comment
Closed

x/tools/go/packages:declared but not used #52345

lvyahui8 opened this issue Apr 14, 2022 · 1 comment
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@lvyahui8
Copy link

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.

image

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

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Apr 14, 2022
@gopherbot gopherbot added this to the Unreleased milestone Apr 14, 2022
@seankhliao
Copy link
Member

Duplicate of #3059

@seankhliao seankhliao marked this as a duplicate of #3059 Apr 14, 2022
@golang golang locked and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants