Fix conversion to pointer

This commit is contained in:
Elara 2022-05-03 18:54:39 -07:00
parent 1269203c08
commit 7ef9e56505
1 changed files with 8 additions and 2 deletions

View File

@ -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