From 0fe6347732bdb9918e3af4e0c4b52f7f0c162894 Mon Sep 17 00:00:00 2001 From: j2gg0s Date: Tue, 27 Aug 2024 14:35:59 +0000 Subject: encoding/json: add embedded structs to the UnmarshalTypeError's Field Including embedded struct inforamtion in error message. Fixes #68941 Change-Id: I6a6f7d506104839a9a7cf1a2c3003272f5534a79 GitHub-Last-Rev: 717f680acafd3f6509c0495f9092e028be502750 GitHub-Pull-Request: golang/go#68966 Reviewed-on: https://go-review.googlesource.com/c/go/+/606956 LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov --- src/encoding/json/decode_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/encoding/json/decode_test.go') diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index 752825cffe..71895a9bb1 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -898,6 +898,19 @@ var unmarshalTests = []struct { }, }, + { + CaseName: Name(""), + in: `{"Level1a": "hello"}`, + ptr: new(Top), + err: &UnmarshalTypeError{ + Value: "string", + Struct: "Top", + Field: "Embed0a.Level1a", + Type: reflect.TypeFor[int](), + Offset: 10, + }, + }, + // issue 15146. // invalid inputs in wrongStringTests below. {CaseName: Name(""), in: `{"B":"true"}`, ptr: new(B), out: B{true}, golden: true}, -- cgit v1.3-6-g1900