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: method Seek() should have signature Seek(int64, int) #36970

Open
sabey opened this issue Feb 1, 2020 · 8 comments
Open

cmd/vet: method Seek() should have signature Seek(int64, int) #36970

sabey opened this issue Feb 1, 2020 · 8 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@sabey
Copy link

sabey commented Feb 1, 2020

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

$ go version
go version go1.13.6 linux/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="/home/jackson/.cache/go-build"
GOENV="/home/jackson/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jackson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build498302187=/tmp/go-build -gno-record-gcc-switches"

What did you do?

func (self *File) Seek(
	offset int64,
) (
	io.Reader,
	error,
) {
	return nil, nil
}

go vet

What did you expect to see?

no error

I do have the package "io" included, but I do also have a Read and Write method which go vet does not complain about

What did you see instead?

./file.go:286:19: method Seek(offset int64) (io.Reader, error) should have signature Seek(int64, int) (int64, error)

@robpike
Copy link
Contributor

robpike commented Feb 1, 2020

Do Read and Write have the correct signatures? Please include a full example, not a snippet.

The error as shown here is correct: the standard Seek method takes two arguments.

@sabey
Copy link
Author

sabey commented Feb 1, 2020

no, Read and Write are different, I only get an error for seek

https://play.golang.org/p/zbCVv7Y8TlE

I just tried it without any reference to io and got the same error:

https://play.golang.org/p/7NFpmLvsh7G

@fzipp
Copy link
Contributor

fzipp commented Feb 2, 2020

no, Read and Write are different, I only get an error for seek

Seek is one of the canonical methods that go vet checks, while Read and Write are not: https://github.com/golang/tools/blob/master/go/analysis/passes/stdmethods/stdmethods.go#L74

If you add a "whence int" parameter to your Seek method and change the type of the first return value from io.Reader to int64 vet will be silent: https://play.golang.org/p/7Pbq67pGGl-

@robpike
Copy link
Contributor

robpike commented Feb 2, 2020

Or just change the name of the function.

@cagedmantis cagedmantis added this to the Backlog milestone Feb 7, 2020
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 7, 2020
@cagedmantis
Copy link
Contributor

/cc @alandonovan @josharian @mvdan

@mvdan
Copy link
Member

mvdan commented Feb 7, 2020

I agree that this seems like a correct vet diagnostic. The io.Seeker interface is defined by itself, so it doesn't matter what other methods your named type has defined.

@sachinkakatkar
Copy link

Facing similar issue at my end while testing prometheus as shown below.

github.com/prometheus/prometheus/storage

./buffer.go:80:34: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
./buffer.go:188:31: method Seek(int64) bool should have signature Seek(int64, int) (int64, error)
./memoized_iterator.go:71:34: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
./merge.go:461:31: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
./series.go:98:31: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
./buffer_test.go:195:30: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
./buffer_test.go:219:31: method Seek(t int64) bool should have signature Seek(int64, int) (int64, error)
FAIL github.com/prometheus/prometheus/storage [build failed]

@timothy-king
Copy link
Contributor

@sachinkakatkar Does renaming the method or changing the signature to conform to io.Seeker work for you?

@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

8 participants