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

Comments

@qdm12
Copy link

@qdm12 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 this to the Unreleased milestone Jul 25, 2021
@hyangah
Copy link
Contributor

@hyangah 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 removed this from the Unreleased milestone Jul 26, 2021
@hyangah hyangah added this to the gopls/v1.0.0 milestone 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
@hyangah hyangah removed this from the gopls/v1.0.0 milestone Jul 28, 2021
@hyangah hyangah added this to the gopls/v0.7.2 milestone Jul 28, 2021
@stamblerre stamblerre removed this from the gopls/v0.7.2 milestone Sep 9, 2021
@stamblerre stamblerre added this to the gopls/on-deck milestone Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants