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

x/tools/gopls: conflicting interfaces states in 'missing method' error instead of 'ambiguous' #47381

Open
qdm12 opened this issue Jul 25, 2021 · 1 comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@qdm12
Copy link
Contributor

qdm12 commented Jul 25, 2021

What did you do?

play.golang.org/p/9aHL-z_QbuL

Here is the code as well:

package main

var _ ConflictingDog = (*Huski)(nil)

type Huski struct {
	Dog
	Barker
}

type ConflictingDog interface {
	Dog
	Barker
}

type Dog interface {
	Bark()
}

type Barker interface {
	Bark()
}

What did you expect to see?

A gopls error suggesting there is a conflict or ambiguity because the interface DogBarker have a conflicting Bark() method from the two interfaces Dog and Barker. The error can be on the variable var _ ConflictingDog = (*Huski)(nil) as it is on play.golang.org, or perhaps on the interface DogBarker directly although I'm not sure about side consequences of this.

What did you see instead?

cannot use (*Huski)(nil) (value of type *Huski) as ConflictingDog value in variable declaration: missing method Bark compiler(InvalidIfaceAssign)

Build info

golang.org/x/tools/gopls v0.7.0
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/go-cmp@v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
    golang.org/x/tools@v0.1.3-0.20210608163600-9ed039809d4c h1:Pv9gNyJFYVdpUAVZYJ1BDSU4eGgXQ+0f3DIGAdolO5s=
    golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
    mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
    mvdan.cc/xurls/v2@v2.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Extra info

  • Gopls log attached: gopls.log
  • Use case: when composing several interfaces and forgetting there is a conflict, the current gopls error is rather misleading and I spent quite some time before figuring it out

Thanks!!

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 25, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jul 25, 2021
@hyangah
Copy link
Contributor

hyangah commented Jul 26, 2021

Thanks for the report @qdm12

I confirm that go list reports both errors, but gopls reports only the second one. The first error is the cause of the second one and should be presented to users. We still need to investigate why the first one was dropped (or never generated).
cc @stamblerre @findleyr

$  go list -e -json -compiled=true -test=true -export=true -deps=true -find=false -- builtin hello.com/...
# hello.com
./main.go:3:5: Huski.Bark is ambiguous
./main.go:3:5: cannot use (*Huski)(nil) (type *Huski) as type ConflictingDog in assignment:
	*Huski does not implement ConflictingDog (missing Bark method)
	...
$ gopls -vv check main.go
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 go env for /Users/hakim/scratch/s
(root /Users/hakim/scratch/s)
(go version go version go1.16.5 darwin/amd64)
(valid build configuration = true)
(build flags: [])
GOCACHE=/Users/hakim/Library/Caches/go-build
GOMODCACHE=/Users/hakim/go/pkg/mod
GOSUMDB=sum.golang.org
GOINSECURE=
GONOSUMDB=
GOPATH=/Users/hakim/go
GO111MODULE=
GONOPROXY=
GOPRIVATE=
GOPROXY=https://proxy.golang.org,direct
GOFLAGS=
GOMOD=/Users/hakim/scratch/s/go.mod
GOROOT=/usr/local/Cellar/go/1.16.5/libexec

2021/07/26 10:37:25 Info:2021/07/26 10:37:25 21.191756ms for GOROOT= GOPATH= GO111MODULE=off GOPROXY= PWD=/Users/hakim/scratch/s go list -e -f {{context.ReleaseTags}} -- unsafe
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 21.87638ms for GOROOT= GOPATH= GO111MODULE=auto GOPROXY= PWD=/Users/hakim/scratch/s go list -modfile=/var/folders/bw/6r6k9d113sv1_vvzk_1kfxbm001py5/T/go.31e5656541cd1399d080165d31fb48b82cb481fae1117ff5f7c8bc0488536c37.201189965.mod -mod=readonly -f "{{context.GOARCH}} {{context.Compiler}}" -- unsafe
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 134.121418ms for GOROOT= GOPATH= GO111MODULE=auto GOPROXY= PWD=/Users/hakim/scratch/s go list -modfile=/var/folders/bw/6r6k9d113sv1_vvzk_1kfxbm001py5/T/go.31e5656541cd1399d080165d31fb48b82cb481fae1117ff5f7c8bc0488536c37.201189965.mod -mod=readonly -e -json -compiled=true -test=true -export=false -deps=true -find=false -- builtin hello.com/...
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 go/packages.Load
	snapshot=0
	directory=/Users/hakim/scratch/s
	query=[builtin hello.com/...]
	packages=2
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 go/packages.Load
	snapshot=0
	package="builtin"
	files=[/usr/local/Cellar/go/1.16.5/libexec/src/builtin/builtin.go]
2021/07/26 10:37:25 Info:2021/07/26 10:37:25 go/packages.Load
	snapshot=0
	package="hello.com"
	files=[/Users/hakim/scratch/s/main.go]
/Users/hakim/scratch/s/main.go:3:24-37: cannot use (*Huski)(nil) (value of type *Huski) as ConflictingDog value in variable declaration: missing method Bark

@hyangah hyangah modified the milestones: Unreleased, gopls/v1.0.0 Jul 26, 2021
@stamblerre stamblerre changed the title x/tools/gopls: Conflicting interfaces states in 'missing method' error instead of 'ambiguous' x/tools/gopls: conflicting interfaces states in 'missing method' error instead of 'ambiguous' Jul 26, 2021
@stamblerre stamblerre added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 26, 2021
@hyangah hyangah modified the milestones: gopls/v1.0.0, gopls/v0.7.2 Jul 28, 2021
@stamblerre stamblerre modified the milestones: gopls/v0.7.2, gopls/on-deck Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants