Fix a bug when binding to pointer #1448
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, this one-line PR fixes a problem when binding to a pointer type and the bind fails. At the moment it tries to set to an incompatible type. Here's example code:
If the param is something that isn't convertible into a float, the return value of the
Bind
call inbinder.go:160
isn'tCanAddr()
, and it tries to return the value itself, instead of a pointer. But because it is a pointer binder, it is supposed to return a pointer. Returning something else will cause it to crash with "can't set a float64 into a variable of type *float64" Fixing it to return a null pointer fixes the problem.There is another, API problem with the binder API though. Bindings can fail, but at the moment, there isn't good ways to detect this failure. It would be great if the
Bind
call would return a boolean that tells whether the binding succeeded or not. As you can see, I'm binding here a float64 type, but I'm using a pointer as a stop-gap resolution to detect when the binding fails.