-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: warn when errors.As target has type *error #47528
Comments
I don't think it break the functions description. It is the purview of any error type to implement It does change the behavior of Lastly, even if it was breaking compatibility, there is a clear exception in the Go 1 compatibility contract for fixing bugs. It is the clear intent of We can still have a vet check to warn about it, but I think the bug should be fixed either way. |
I was referring to:
The value here is assignable as types match. Having sentinel errors assignable in turn is more because we can't have |
But the complete paragraph is
The existence of the |
Well, this is surprising behavior to me. I would've expected |
That does indeed seem to contradict the wording of |
Perhaps That is pretty much guaranteed to indicate a bug, because it is trivially true that the first argument (of type |
The relevant wording is: "An error matches target if the error's concrete value is assignable to the value pointed to by target" In this case, the target has type |
@neild I'm not really trying to nitpick wording, but I think it is unexpected that an error might have an |
(If I were to nitpick wording, I'd argue that "X is the case if A or B. In the latter case, the method As is responsible…" seems to imply to me, that |
I think the current behavior is appropriate, if for no other reason than that pre- |
It was (for better or worse) an intentional choice that |
Fair enough. I find it very strange, but I guess I'm too late for that discussion. Then perhaps the issue should be re-titled again, as the |
Change https://golang.org/cl/339889 mentions this issue: |
This proposal has been added to the active column of the proposals project |
Would it make sense to apply the same warning to pointers to empty interface types, too? |
Warning on |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
The proposal is accepted and has an open CL. Any chance to move the CL forward? |
Change https://go.dev/cl/403034 mentions this issue: |
A new testdata file was added since CL 339889 was authored. Update it in the same way for the new warning. Updates golang/go#47528. Fixes golang/go#52613. Change-Id: I17d06c602eeabcc4ddc8514d5e444acdb714ab94 Reviewed-on: https://go-review.googlesource.com/c/tools/+/403034 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Tim King <taking@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What did you do?
Wrote this code https://play.golang.org/p/16cU0kc8Lku and wondered why the errors matched.
Discussion in https://groups.google.com/g/golang-nuts/c/MaYJy_IRbYA/m/uCHV6P87EQAJ?utm_medium=email&utm_source=footer
What did you expect to see?
Of course the code above is wrong, yet I didn't spot it. It would be nice if this kind of programming error could be detected:
govet
check that flags using plainerror
s witherrors.As
orerrors.errorString
should implementAs()
and returnfalse
, unless the pointers match.I'm unsure if the latter is possible. It would strictly break BC (and the function's description). On the other hand ist should only change behaviour in cases that seem invalid from the start?
The text was updated successfully, but these errors were encountered: