Commit a50b471b authored by gary rong's avatar gary rong Committed by Guillaume Ballet

accounts/abi: allow interface as the destination (#18490)

parent ad849c01
...@@ -74,7 +74,7 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value { ...@@ -74,7 +74,7 @@ func mustArrayToByteSlice(value reflect.Value) reflect.Value {
func set(dst, src reflect.Value) error { func set(dst, src reflect.Value) error {
dstType, srcType := dst.Type(), src.Type() dstType, srcType := dst.Type(), src.Type()
switch { switch {
case dstType.Kind() == reflect.Interface: case dstType.Kind() == reflect.Interface && dst.Elem().IsValid():
return set(dst.Elem(), src) return set(dst.Elem(), src)
case dstType.Kind() == reflect.Ptr && dstType.Elem() != derefbigT: case dstType.Kind() == reflect.Ptr && dstType.Elem() != derefbigT:
return set(dst.Elem(), src) return set(dst.Elem(), src)
......
...@@ -512,6 +512,11 @@ func TestMethodMultiReturn(t *testing.T) { ...@@ -512,6 +512,11 @@ func TestMethodMultiReturn(t *testing.T) {
Int *big.Int Int *big.Int
} }
newInterfaceSlice := func(len int) interface{} {
slice := make([]interface{}, len)
return &slice
}
abi, data, expected := methodMultiReturn(require.New(t)) abi, data, expected := methodMultiReturn(require.New(t))
bigint := new(big.Int) bigint := new(big.Int)
var testCases = []struct { var testCases = []struct {
...@@ -539,6 +544,16 @@ func TestMethodMultiReturn(t *testing.T) { ...@@ -539,6 +544,16 @@ func TestMethodMultiReturn(t *testing.T) {
&[2]interface{}{&expected.Int, &expected.String}, &[2]interface{}{&expected.Int, &expected.String},
"", "",
"Can unpack into an array", "Can unpack into an array",
}, {
&[2]interface{}{},
&[2]interface{}{expected.Int, expected.String},
"",
"Can unpack into interface array",
}, {
newInterfaceSlice(2),
&[]interface{}{expected.Int, expected.String},
"",
"Can unpack into interface slice",
}, { }, {
&[]interface{}{new(int), new(int)}, &[]interface{}{new(int), new(int)},
&[]interface{}{&expected.Int, &expected.String}, &[]interface{}{&expected.Int, &expected.String},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment