x/params/types: make KeyTable.RegisterType fully dereference pointers (#6915)
Use a for loop to correctly and fully dereference and extract the type for the type of ParamSetPair.Value. Fixes #6785 Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
c7c66f8b36
commit
10d330e5b1
|
@ -0,0 +1,27 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestKeyTableUnfurlsPointers(t *testing.T) {
|
||||
tbl := NewKeyTable()
|
||||
validator := func(_ interface{}) error {
|
||||
return nil
|
||||
}
|
||||
tbl = tbl.RegisterType(ParamSetPair{
|
||||
Key: []byte("key"),
|
||||
Value: (*****string)(nil),
|
||||
ValidatorFn: validator,
|
||||
})
|
||||
|
||||
got := tbl.m["key"]
|
||||
want := attribute{
|
||||
vfn: validator,
|
||||
ty: reflect.ValueOf("").Type(),
|
||||
}
|
||||
require.Equal(t, got.ty, want.ty)
|
||||
}
|
|
@ -48,7 +48,7 @@ func (t KeyTable) RegisterType(psp ParamSetPair) KeyTable {
|
|||
rty := reflect.TypeOf(psp.Value)
|
||||
|
||||
// indirect rty if it is a pointer
|
||||
if rty.Kind() == reflect.Ptr {
|
||||
for rty.Kind() == reflect.Ptr {
|
||||
rty = rty.Elem()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue