From 44acf23df958bb334a7249e2f03a1d6e81cff1cb Mon Sep 17 00:00:00 2001 From: devopsbo3 <69951731+devopsbo3@users.noreply.github.com> Date: Fri, 10 Nov 2023 12:27:53 -0600 Subject: [PATCH] Revert "account/abi: convert if-else-if chain to tagged switch (#27869)" This reverts commit c8563890cba0bd4522c48fba59c4be1dca3bcc79. --- accounts/abi/method.go | 7 +++---- accounts/abi/method_test.go | 7 +++---- accounts/abi/unpack.go | 7 +++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/accounts/abi/method.go b/accounts/abi/method.go index b6e1eef3cf..f69e3ee9b5 100644 --- a/accounts/abi/method.go +++ b/accounts/abi/method.go @@ -127,12 +127,11 @@ func NewMethod(name string, rawName string, funType FunctionType, mutability str state = state + " " } identity := fmt.Sprintf("function %v", rawName) - switch funType { - case Fallback: + if funType == Fallback { identity = "fallback" - case Receive: + } else if funType == Receive { identity = "receive" - case Constructor: + } else if funType == Constructor { identity = "constructor" } str := fmt.Sprintf("%v(%v) %sreturns(%v)", identity, strings.Join(inputNames, ", "), state, strings.Join(outputNames, ", ")) diff --git a/accounts/abi/method_test.go b/accounts/abi/method_test.go index 9230e307aa..395a528965 100644 --- a/accounts/abi/method_test.go +++ b/accounts/abi/method_test.go @@ -84,12 +84,11 @@ func TestMethodString(t *testing.T) { for _, test := range table { var got string - switch test.method { - case "fallback": + if test.method == "fallback" { got = abi.Fallback.String() - case "receive": + } else if test.method == "receive" { got = abi.Receive.String() - default: + } else { got = abi.Methods[test.method].String() } if got != test.expectation { diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go index 905b5ce629..68451483cd 100644 --- a/accounts/abi/unpack.go +++ b/accounts/abi/unpack.go @@ -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 var refSlice reflect.Value - switch t.T { - case SliceTy: + if t.T == SliceTy { // declare our slice refSlice = reflect.MakeSlice(t.GetType(), size, size) - case ArrayTy: + } else if t.T == ArrayTy { // declare our array refSlice = reflect.New(t.GetType()).Elem() - default: + } else { return nil, errors.New("abi: invalid type in array/slice unpacking stage") }