Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue: simplify the reflect checks in Value.Decode
reflect.Value.CanSet is documented as: A Value can be changed only if it is addressable and was not obtained by the use of unexported struct fields. We call reflect.ValueOf ourselves here, so we cannot have reached for an unexported struct field via reflect.Value.Field. The only other requirement is that the value must be addressable, which can only be met if x was a non-nil pointer that we dereferenced. This was already the expectation that Decode had on x; it just wasn't documented very clearly, but now it is. We can then replace the CanSet check with a check for a non-nil pointer, which exactly matches the logic from APIs like encoding/json.Unmarshal. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I919026530c683a2c9b10f1484910f9cb66fee861 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168928 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information