diff --git a/internal/serde/reflect.go b/internal/serde/reflect.go index 9d828ce..6c60488 100644 --- a/internal/serde/reflect.go +++ b/internal/serde/reflect.go @@ -445,8 +445,7 @@ func serializeInterface(s *Serializer, t reflect.Type, p unsafe.Pointer) { return } - x := *(*interface{})(p) - et := reflect.TypeOf(x) + et := reflect.TypeOf(reflect.NewAt(t, p).Elem().Interface()) serializeType(s, et) eptr := i.ptr diff --git a/internal/serde/scan.go b/internal/serde/scan.go index 69a0914..2827364 100644 --- a/internal/serde/scan.go +++ b/internal/serde/scan.go @@ -278,9 +278,9 @@ func scan(s *Serializer, t reflect.Type, p unsafe.Pointer) { scan(s, et, ep) } case reflect.Interface: - x := *(*interface{})(p) - et := reflect.TypeOf(x) + et := reflect.TypeOf(r.Elem().Interface()) eptr := (*iface)(p).ptr + if eptr == nil { return } diff --git a/serde/serde_test.go b/serde/serde_test.go index f1cb3d3..d9b7c0a 100644 --- a/serde/serde_test.go +++ b/serde/serde_test.go @@ -2,6 +2,7 @@ package serde_test import ( "bytes" + "context" "encoding/binary" "fmt" "net/http" @@ -26,6 +27,7 @@ func TestReflect(t *testing.T) { intv := int(100) intp := &intv intpp := &intp + type ctxKey1 struct{} cases := []any{ "foo", @@ -63,6 +65,10 @@ func TestReflect(t *testing.T) { func(int) int { return 42 }, [1]*int{intp}, + + context.Background(), + context.TODO(), + context.WithValue(context.Background(), ctxKey1{}, "hello"), } for _, x := range cases {