lang: interfaces: Nil input means no args

This commit is contained in:
James Shubin
2024-10-06 22:51:48 -04:00
parent 6c12e8a29b
commit b03fdeccae

View File

@@ -391,8 +391,9 @@ type Txn interface {
// StructToCallableArgs transforms the single value, graph representation of the // StructToCallableArgs transforms the single value, graph representation of the
// callable values into a linear, standard args list. // callable values into a linear, standard args list.
func StructToCallableArgs(st types.Value) ([]types.Value, error) { func StructToCallableArgs(st types.Value) ([]types.Value, error) {
if st == nil { args := []types.Value{}
return nil, fmt.Errorf("empty struct") if st == nil { // for functions that take no args
return args, nil
} }
typ := st.Type() typ := st.Type()
if typ == nil { if typ == nil {
@@ -406,7 +407,6 @@ func StructToCallableArgs(st types.Value) ([]types.Value, error) {
return nil, fmt.Errorf("empty values") return nil, fmt.Errorf("empty values")
} }
args := []types.Value{}
for i, x := range typ.Ord { // in the correct order for i, x := range typ.Ord { // in the correct order
v, exists := structValues[x] v, exists := structValues[x]
if !exists { if !exists {