diff options
author | Damian Gryski <[email protected]> | 2023-03-11 23:00:09 -0800 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-19 17:45:43 +0100 |
commit | 229f479a7dab1358f0fd4abecb20751430f56103 (patch) | |
tree | 884aba4d36adeffe9a90853168ab63062c8d163f | |
parent | 876f08979f0aee9b6ebb66603c76cdcc1e4729eb (diff) | |
download | tinygo-229f479a7dab1358f0fd4abecb20751430f56103.tar.gz tinygo-229f479a7dab1358f0fd4abecb20751430f56103.zip |
reflect: make sure pointerTo() works for named types
-rw-r--r-- | src/reflect/type.go | 4 | ||||
-rw-r--r-- | src/reflect/value_test.go | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/reflect/type.go b/src/reflect/type.go index cc79a7095..4999afddd 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -490,6 +490,10 @@ func PointerTo(t Type) Type { } func pointerTo(t *rawType) *rawType { + if t.isNamed() { + return (*elemType)(unsafe.Pointer(t)).ptrTo + } + switch t.Kind() { case Pointer: // TODO(dgryski): This is blocking https://github.com/tinygo-org/tinygo/issues/3131 diff --git a/src/reflect/value_test.go b/src/reflect/value_test.go index c915a36db..2bc8f9275 100644 --- a/src/reflect/value_test.go +++ b/src/reflect/value_test.go @@ -275,6 +275,14 @@ func TestNamedTypes(t *testing.T) { t.Errorf("Type.String(base64.Encoding{})=%v, want %v", got, want) } + type Repository struct { + RoleName *string `json:"role_name,omitempty"` + } + + var repo *Repository + v := ValueOf(&repo).Elem() + n := New(v.Type().Elem()) + v.Set(n) } func TestStruct(t *testing.T) { |