Revert "account/abi: convert if-else-if chain to tagged switch (#27869)"

This reverts commit c8563890cb.
This commit is contained in:
devopsbo3 2023-11-10 12:27:53 -06:00 committed by GitHub
parent 14db2e93b8
commit 44acf23df9
3 changed files with 9 additions and 12 deletions

View file

@ -127,12 +127,11 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str
state = state + " " state = state + " "
} }
identity := fmt.Sprintf("function %v", rawName) identity := fmt.Sprintf("function %v", rawName)
switch funType { if funType == Fallback {
case Fallback:
identity = "fallback" identity = "fallback"
case Receive: } else if funType == Receive {
identity = "receive" identity = "receive"
case Constructor: } else if funType == Constructor {
identity = "constructor" identity = "constructor"
} }
str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", ")) str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", "))

View file

@ -84,12 +84,11 @@ func TestMethodString(t *testing.T) {
for _, test := range table { for _, test := range table {
var got string var got string
switch test.method { if test.method == "fallback" {
case "fallback":
got = abi.Fallback.String() got = abi.Fallback.String()
case "receive": } else if test.method == "receive" {
got = abi.Receive.String() got = abi.Receive.String()
default: } else {
got = abi.Methods[test.method].String() got = abi.Methods[test.method].String()
} }
if got != test.expectation { if got != test.expectation {

View file

@ -160,14 +160,13 @@ func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error)
// this value will become our slice or our array, depending on the type // this value will become our slice or our array, depending on the type
var refSlice reflect.Value var refSlice reflect.Value
switch t.T { if t.T == SliceTy {
case SliceTy:
// declare our slice // declare our slice
refSlice = reflect.MakeSlice(t.GetType(), size, size) refSlice = reflect.MakeSlice(t.GetType(), size, size)
case ArrayTy: } else if t.T == ArrayTy {
// declare our array // declare our array
refSlice = reflect.New(t.GetType()).Elem() refSlice = reflect.New(t.GetType()).Elem()
default: } else {
return nil, errors.New("abi: invalid type in array/slice unpacking stage") return nil, errors.New("abi: invalid type in array/slice unpacking stage")
} }