aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json/decode.go')
-rw-r--r--src/encoding/json/decode.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go
index 4f98916105..536f25dc7c 100644
--- a/src/encoding/json/decode.go
+++ b/src/encoding/json/decode.go
@@ -707,6 +707,19 @@ func (d *decodeState) object(v reflect.Value) {
for _, i := range f.index {
if subv.Kind() == reflect.Ptr {
if subv.IsNil() {
+ // If a struct embeds a pointer to an unexported type,
+ // it is not possible to set a newly allocated value
+ // since the field is unexported.
+ //
+ // See https://golang.org/issue/21357
+ if !subv.CanSet() {
+ d.saveError(fmt.Errorf("json: cannot set embedded pointer to unexported struct: %v", subv.Type().Elem()))
+ // Invalidate subv to ensure d.value(subv) skips over
+ // the JSON value without assigning it to subv.
+ subv = reflect.Value{}
+ destring = false
+ break
+ }
subv.Set(reflect.New(subv.Type().Elem()))
}
subv = subv.Elem()