This commit is contained in:
Martin Holst Swende
2017-12-21 16:18:37 +01:00
parent 73d4a57d47
commit c095c87e11
5 changed files with 128 additions and 47 deletions

View File

@ -93,3 +93,20 @@ func requireAssignable(dst, src reflect.Value) error {
}
return nil
}
// requireUnpackKind verifies preconditions for unpacking `args` into `kind`
func requireUnpackKind(v reflect.Value, t reflect.Type, k reflect.Kind,
args Arguments) error {
switch k {
case reflect.Struct:
case reflect.Slice, reflect.Array:
if minLen := args.LengthNonIndexed(); v.Len() < minLen {
return fmt.Errorf("abi: insufficient number of elements in the list/array for unpack, want %d, got %d",
minLen, v.Len())
}
default:
return fmt.Errorf("abi: cannot unmarshal tuple into %v", t)
}
return nil
}