-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
errors, cmd/vet: too easy to pass a pointer-to-pointer to errors.As
when it should be a pointer-to-value
#34091
Comments
Ps: this comment on 29054 suggests that this should work (or something like it). |
After a bit of navel gazing, providing e3 := syscall.Errno(1)
var se2 syscall.Errno
fmt.Println("Type of e3 is: ", reflect.TypeOf(e3))
if errors.As(e3, &se2) {
fmt.Println("Found a syscall.Errno in e3")
} but trying to call se2.Error() = Operation not permitted I've updated the playground. |
Yes, that's because errno go/src/syscall/zerrors_linux_amd64.go Lines 1381 to 1382 in 50bd1c4
|
go/src/cmd/go/internal/robustio/robustio_windows.go Lines 95 to 97 in aae0b5b
That said, I think there should be a |
errors.As
when it should be a pointer-to-value
CC @jba @neild @ianthehat |
There already seems to be a check for exactly this: The problem here is that This playground snippet should highlight this: https://play.golang.org/p/Gzf3XV_RXEY. The errorsas vet check could be expanded to explicitly check for |
@tmthrgd, a more precise generic check would presumably flag the use of The question then is, are there any value types that implement |
Sigh. Thanks for clearing that bit up.... |
The same problem exists when using type assertions: if _, ok := err.(*syscall.Errno); ok {
fmt.Println("Found a *syscall.Errno")
}
if _, ok := err.(syscall.Errno); ok {
fmt.Println("Found a syscall.Errno")
} One of these type assertions is clearly wrong, but the compiler can't tell you which. This is a good reason to always define I think that if the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
I am using the latest release.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I've been exploring the new
errors.As()
and wasn't able to get it to recognize a wrappedsyscall.Errno
. I've distilled a simpler case. Here is a playground linkWhat did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: