Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lists: Fix handling of go arrays #894

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion common/types/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ func (l *baseList) ConvertToNative(typeDesc reflect.Type) (any, error) {
// Allow the element ConvertToNative() function to determine whether conversion is possible.
otherElemType := typeDesc.Elem()
elemCount := l.size
nativeList := reflect.MakeSlice(typeDesc, elemCount, elemCount)
var nativeList reflect.Value
if typeDesc.Kind() == reflect.Array {
nativeList = reflect.New(reflect.ArrayOf(elemCount, typeDesc)).Elem().Index(0)
} else {
nativeList = reflect.MakeSlice(typeDesc, elemCount, elemCount)

}
for i := 0; i < elemCount; i++ {
elem := l.NativeToValue(l.get(i))
nativeElemVal, err := elem.ConvertToNative(otherElemType)
Expand Down
11 changes: 11 additions & 0 deletions ext/native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func TestNativeTypes(t *testing.T) {
NestedMapVal: {42: true},
},
],
ArrayVal: [
ext.TestNestedType{
NestedListVal:['goodbye', 'cruel', 'world'],
NestedMapVal: {42: true},
},
],
MapVal: {'map-key': ext.TestAllTypes{BoolVal: true}},
CustomSliceVal: [ext.TestNestedSliceType{Value: 'none'}],
CustomMapVal: {'even': ext.TestMapVal{Value: 'more'}},
Expand All @@ -85,6 +91,10 @@ func TestNativeTypes(t *testing.T) {
NestedMapVal: map[int64]bool{42: true},
},
},
ArrayVal: [1]*TestNestedType{{
NestedListVal: []string{"goodbye", "cruel", "world"},
NestedMapVal: map[int64]bool{42: true},
}},
MapVal: map[string]TestAllTypes{"map-key": {BoolVal: true}},
CustomSliceVal: []TestNestedSliceType{{Value: "none"}},
CustomMapVal: map[string]TestMapVal{"even": {Value: "more"}},
Expand Down Expand Up @@ -688,6 +698,7 @@ type TestAllTypes struct {
Uint32Val uint32
Uint64Val uint64
ListVal []*TestNestedType
ArrayVal [1]*TestNestedType
MapVal map[string]TestAllTypes
PbVal *proto3pb.TestAllTypes
CustomSliceVal []TestNestedSliceType
Expand Down