-
Notifications
You must be signed in to change notification settings - Fork 672
How to fix shadowing introduced by decodeBasic in v1.3.2? #290
Comments
Hi. I've been trying to fix it lately and this is what I got: What happened in v1.3.2?Looking at the func wrapper(query map[string]interface{}, r interface{}) error {
fmt.Printf("before caller:\n%#v\n", r)
fmt.Printf(" address of r: %p\n", &r)
fmt.Printf(" address of resp: %p\n", r)
err := caller(query, &r)
fmt.Printf("after caller:\n%#v\n", r)
fmt.Printf(" address of r: %p\n", &r)
fmt.Printf(" address of resp: %p\n", r)
return err
} output
Why
|
So the actual cause of the issue is that a mapstructure no longer works on a pointer to a pointer to a struct, where it used to do so. It's possible that mapstructure might itself detect that when it encounters that case and dereference the outer pointer? |
Hi,
I came across an interesting side-effect of the changes introduced in v1.3.2 in the
decodeBasic
function (93663c4) in the 99designs/gqlgen codebase. The following reproducer runs fine prior the version mentioned before, but fails for the versions since.Reproducer
Output with v1.3.1
Output with v1.3.2
The debugger says that
resp
is shadowed inwrapCaller
and the nil value is returned, although one level down incaller
everything looks fine. I believe this case is not covered by the unit tests inmapstructure_test.go
.I'm really interested to understand why this is happening, the mechanics in the background and how to solve it.
The text was updated successfully, but these errors were encountered: