From 7ef9e56505d2cc1492b80ed7f17a1df336606c67 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Tue, 3 May 2022 18:54:39 -0700 Subject: [PATCH] Fix conversion to pointer --- internal/reflectutil/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/reflectutil/utils.go b/internal/reflectutil/utils.go index 20a7a0a..6a4f94b 100644 --- a/internal/reflectutil/utils.go +++ b/internal/reflectutil/utils.go @@ -38,8 +38,14 @@ func Convert(in reflect.Value, toType reflect.Type) (reflect.Value, error) { // If the output type is a pointer to the input type if reflect.PtrTo(inType) == toType { - // Return pointer to input - return in.Addr(), nil + if in.CanAddr() { + // Return pointer to input + return in.Addr(), nil + } + + inPtrVal := reflect.New(inType) + inPtrVal.Elem().Set(in) + return inPtrVal, nil } // If input is a pointer pointing to the output type