Skip to content

Commit a50b471

Browse files
rjl493456442gballet
authored andcommittedJan 23, 2019
accounts/abi: allow interface as the destination (ethereum#18490)
1 parent ad849c0 commit a50b471

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎accounts/abi/reflect.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value {
7474
func set(dst, src reflect.Value) error {
7575
dstType, srcType := dst.Type(), src.Type()
7676
switch {
77-
case dstType.Kind() == reflect.Interface:
77+
case dstType.Kind() == reflect.Interface && dst.Elem().IsValid():
7878
return set(dst.Elem(), src)
7979
case dstType.Kind() == reflect.Ptr && dstType.Elem() != derefbigT:
8080
return set(dst.Elem(), src)

‎accounts/abi/unpack_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,11 @@ func TestMethodMultiReturn(t *testing.T) {
512512
Int *big.Int
513513
}
514514

515+
newInterfaceSlice := func(len int) interface{} {
516+
slice := make([]interface{}, len)
517+
return &slice
518+
}
519+
515520
abi, data, expected := methodMultiReturn(require.New(t))
516521
bigint := new(big.Int)
517522
var testCases = []struct {
@@ -539,6 +544,16 @@ func TestMethodMultiReturn(t *testing.T) {
539544
&[2]interface{}{&expected.Int, &expected.String},
540545
"",
541546
"Can unpack into an array",
547+
}, {
548+
&[2]interface{}{},
549+
&[2]interface{}{expected.Int, expected.String},
550+
"",
551+
"Can unpack into interface array",
552+
}, {
553+
newInterfaceSlice(2),
554+
&[]interface{}{expected.Int, expected.String},
555+
"",
556+
"Can unpack into interface slice",
542557
}, {
543558
&[]interface{}{new(int), new(int)},
544559
&[]interface{}{&expected.Int, &expected.String},

0 commit comments

Comments
 (0)
Please sign in to comment.