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/compile: report variable declared but not used when only a field of a struct-typed variable is written to #50778

Closed
qiangli opened this issue Jan 24, 2022 · 4 comments
Labels
NeedsInvestigation
Milestone

Comments

@qiangli
Copy link

@qiangli qiangli commented Jan 24, 2022

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

$ go version

go version go1.16.7 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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/go/pkg/mod"
GONOPROXY="github.com/myurl/"
GONOSUMDB="github.com/myurl/
"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPRIVATE="github.com/myurl/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/user/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/user/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/user/bug/go.mod"
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/2r/7l5dccss0y74mcl41nqbpyfm6h04p

What did you do?

It is desired that an error be reported when running go vet/build with the following code:

package main

import (
	"net/url"
)

func main() {
	s := "https://example.com"
	myUrl, err := url.Parse(s)
	if err != nil {
		panic(err)
	}
        // myUrl is used but not really.
	myUrl.Scheme = "http"
}

What did you expect to see?

myUrl declared but not used

What did you see instead?

No error.

@mknyszek mknyszek changed the title Not able to detect "variable declared but not used" cmd/compile: report variable declared but not used when only a field of a struct-typed variable is written to Jan 24, 2022
@mknyszek mknyszek added the NeedsInvestigation label Jan 24, 2022
@mknyszek mknyszek added this to the Backlog milestone Jan 24, 2022
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Jan 24, 2022

Duplicate of #449

@seankhliao seankhliao marked this as a duplicate of #449 Jan 24, 2022
@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Jan 24, 2022

I don't think that this is going to be possible to add now because it'll cause programs that previously compiled to no longer compile which breaks the Go 1 backwards compatibility promise.

@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Jan 24, 2022

@seankhliao Good catch!

@mknyszek
Copy link
Contributor

@mknyszek mknyszek commented Jan 24, 2022

And yes, as the other bug says, a vet check is reasonable and won't break backwards compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants