diff options
Diffstat (limited to 'accounts/abi/error.go')
-rw-r--r-- | accounts/abi/error.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/accounts/abi/error.go b/accounts/abi/error.go index 420acf418..9d8674ad0 100644 --- a/accounts/abi/error.go +++ b/accounts/abi/error.go @@ -39,22 +39,23 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string { // type in t. func sliceTypeCheck(t Type, val reflect.Value) error { if val.Kind() != reflect.Slice && val.Kind() != reflect.Array { - return typeErr(formatSliceString(t.Kind, t.SliceSize), val.Type()) + return typeErr(formatSliceString(t.Kind, t.Size), val.Type()) } - if t.IsArray && val.Len() != t.SliceSize { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), formatSliceString(val.Type().Elem().Kind(), val.Len())) + + if t.T == ArrayTy && val.Len() != t.Size { + return typeErr(formatSliceString(t.Elem.Kind, t.Size), formatSliceString(val.Type().Elem().Kind(), val.Len())) } - if t.Elem.IsSlice { + if t.Elem.T == SliceTy { if val.Len() > 0 { return sliceTypeCheck(*t.Elem, val.Index(0)) } - } else if t.Elem.IsArray { + } else if t.Elem.T == ArrayTy { return sliceTypeCheck(*t.Elem, val.Index(0)) } if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Kind { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), val.Type()) + return typeErr(formatSliceString(t.Elem.Kind, t.Size), val.Type()) } return nil } @@ -62,20 +63,19 @@ func sliceTypeCheck(t Type, val reflect.Value) error { // typeCheck checks that the given reflection value can be assigned to the reflection // type in t. func typeCheck(t Type, value reflect.Value) error { - if t.IsSlice || t.IsArray { + if t.T == SliceTy || t.T == ArrayTy { return sliceTypeCheck(t, value) } // Check base type validity. Element types will be checked later on. if t.Kind != value.Kind() { return typeErr(t.Kind, value.Kind()) + } else if t.T == FixedBytesTy && t.Size != value.Len() { + return typeErr(t.Type, value.Type()) + } else { + return nil } - return nil -} -// varErr returns a formatted error. -func varErr(expected, got reflect.Kind) error { - return typeErr(expected, got) } // typeErr returns a formatted type casting error. |