cmd/vet: reject json.Unmarshal(data, non-pointer) #27564
Closed
Milestone
Comments
The way to reject this code early would be with cmd/vet. This would apply to gob and xml too, of course: you can't unmarshal into a non-(pointer or interface). |
I've made a start on implementing this check. |
Change https://golang.org/cl/139997 mentions this issue: |
Change https://golang.org/cl/148562 mentions this issue: |
gopherbot
pushed a commit
to golang/tools
that referenced
this issue
Nov 9, 2018
The checker has been modified to avoid making two memory allocations for every CallExpr in the program. Originally: https://go-review.googlesource.com/c/139997 Updates golang/go#27564 Change-Id: I168869272a1d78d47d84c049aba619bb223cad70 Reviewed-on: https://go-review.googlesource.com/c/148562 Reviewed-by: Michael Matloob <matloob@golang.org>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Here is a snippet from
encoding/json
In that snippet
v
is aninterface{}
. So it can be anything. But it needs to be a pointer to receive the unmarshaled value.If we don't use a pointer we will get a runtime error. And it's must be a pointer.
Can we add a build tag to throw error when a interface is not a pointer?
So that, we can get a compile time error if that interface must be a pointer instead of runtime error.
The text was updated successfully, but these errors were encountered: