Skip to content

Commit dc9c0d2

Browse files
author
Patrick Pichler
committed
Use bytes interface value for zero native type struct fields instead of dynamic list
If a struct has a byte array/slice field and it happens to be the zero value, a dynamic list object was returned. This caused issues with functions taking `Bytes` via arguments, as the type checker will accept such functions, but they might fail at runtime. To work around this, the raw bytes array/slice is returned in case of an zero value.
1 parent 21976cf commit dc9c0d2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ext/native.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ func getFieldValue(adapter types.Adapter, refField reflect.Value) any {
711711
if refField.IsZero() {
712712
switch refField.Kind() {
713713
case reflect.Array, reflect.Slice:
714+
if refField.Type().Elem() == reflect.TypeOf(byte(0)) {
715+
return refField.Interface()
716+
}
714717
return types.NewDynamicList(adapter, []ref.Val{})
715718
case reflect.Map:
716719
return types.NewDynamicMap(adapter, map[ref.Val]ref.Val{})

0 commit comments

Comments
 (0)