aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2023-03-18 22:55:02 -0700
committerRon Evans <[email protected]>2023-03-19 20:37:57 +0100
commit6fbe6fa2ae1e41ce77c8be38b542c382caaecb96 (patch)
tree9a95548c0fdb5417404b04a3032b9898d9b3cd12
parent24b4dc31a4c18f9edb584b459de03dd05d3ffcb3 (diff)
downloadtinygo-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.go5
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()