-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: go vet reports error: impossible type assertion: no type can implement both... for generic interface
#50658
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
Comments
I agree that it doesn't seem like this code should have an error. |
impossible type assertion: no type can implement both... for generic interface
I can only reproduce this with |
cc: @findleyr |
Yes, this looks like a problem with Thank you for filing. We will investigate. |
I can confirm that I can reproduce with ATM In this context, I think what we want to know is whether there does not exist a type instantiations s.t. V is an implementation of U. @griesemer and @findleyr how feasible is this to check? Here is an example to showcase that we care about both potentially being type parameters.
A quick-n-dirty solution is to not check interfaces that contain any type parameters in |
Hmm. This is rather tricky. In order to make it possible for tools to do this type of analysis correctly, we'd need to expose some sort of unification API. In this case, we'd need to see if there is a potential unification that allows this type assertion. For 1.18, I think we should suppress the error message if either of the signatures in question are parameterized by type parameters. |
@timothy-king submitted https://go.dev/cl/380014 to address this issue, so we can close this once we've re-vendored x/tools. |
Change https://golang.org/cl/380777 mentions this issue: |
Update the vendored x/tools to pick up CL 380014, which updates the ifaceassert vet analyzer to remove spurious errors for assertions involving interfaces with type parameters. This also picks up some superficial changes related to refactoring of the x/tools/internal/typeparams API. The following commands were used: go get -d golang.org/x/tools@master go mod tidy go mod vendor Fixes golang#50658 Change-Id: I2f612fd186a1a260cab21860b192c9f6dc3f560f Reviewed-on: https://go-review.googlesource.com/c/go/+/380777 Trust: Robert Findley <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Tim King <[email protected]>
What version of Go are you using (
go version
)?1.18beta1
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am using a generic interface the following way:
What did you expect to see?
No error message.
What did you see instead?
When building or using
go test ./...
, I have the following message:impossible type assertion: no type can implement both gogenerics.Doer[T] and gogenerics.Doer[float32] (conflicting types for Do method)
The error message also appears in VSCode (with the syntax highlighter using gopls with generics enabled).
I must emphasize that this code works perfectly well if imported from other modules ; the only isssue is when using the module "from itself".
The text was updated successfully, but these errors were encountered: