From ed749f75ddc3c29ae1c8f4a0d0d4aefc596c4a2f Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Tue, 19 Sep 2023 13:46:29 -0400 Subject: [PATCH] Fix inlined arrays Arrays of size 1 with inlined type are inlined in interfaces. This test would panic before. https://cs.opensource.google/go/go/+/master:src/cmd/compile/internal/types/type.go;l=1824-1826;drc=cc904eb0e87a00430bec8d1918f649638553e5de --- internal/serde/unsafe.go | 2 ++ serde/serde_test.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/internal/serde/unsafe.go b/internal/serde/unsafe.go index 3ef65b8..ecdc18a 100644 --- a/internal/serde/unsafe.go +++ b/internal/serde/unsafe.go @@ -30,6 +30,8 @@ func inlined(t reflect.Type) bool { return true case reflect.Struct: return t.NumField() == 1 && inlined(t.Field(0).Type) + case reflect.Array: + return t.Len() == 1 && inlined(t.Elem()) default: return false } diff --git a/serde/serde_test.go b/serde/serde_test.go index c83da07..cf58894 100644 --- a/serde/serde_test.go +++ b/serde/serde_test.go @@ -61,6 +61,8 @@ func TestReflect(t *testing.T) { func() {}, func(int) int { return 42 }, + + [1]*int{intp}, } for _, x := range cases {