diff options
author | Damian Gryski <[email protected]> | 2023-03-18 22:55:02 -0700 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-19 20:37:57 +0100 |
commit | 6fbe6fa2ae1e41ce77c8be38b542c382caaecb96 (patch) | |
tree | 9a95548c0fdb5417404b04a3032b9898d9b3cd12 | |
parent | 24b4dc31a4c18f9edb584b459de03dd05d3ffcb3 (diff) | |
download | tinygo-6fbe6fa2ae1e41ce77c8be38b542c382caaecb96.tar.gz tinygo-6fbe6fa2ae1e41ce77c8be38b542c382caaecb96.zip |
reflect: tweak Type.String() to match what encoding/json expects for empty structs
-rw-r--r-- | src/reflect/type.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go index 01838a9a7..1d13fa0e2 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -527,8 +527,11 @@ func (t *rawType) String() string { case Map: return "map[" + t.key().String() + "]" + t.elem().String() case Struct: - s := "struct {" numField := t.NumField() + if numField == 0 { + return "struct {}" + } + s := "struct {" for i := 0; i < numField; i++ { f := t.rawField(i) s += " " + f.Name + " " + f.Type.String() |