Skip to content

Commit

Permalink
Use 'any' inplace of 'interface{}'
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Jun 6, 2022
1 parent be61352 commit 113ec7c
Show file tree
Hide file tree
Showing 57 changed files with 343 additions and 343 deletions.
124 changes: 62 additions & 62 deletions encoding/json/decode.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (e *Encoder) Encode(value cadence.Value) (err error) {

// JSON struct definitions

type jsonValue interface{}
type jsonValue any

type jsonValueObject struct {
Type string `json:"type"`
Expand Down Expand Up @@ -333,7 +333,7 @@ func prepareVoid() jsonValue {
}

func prepareOptional(v cadence.Optional) jsonValue {
var value interface{}
var value any

if v.Value != nil {
value = Prepare(v.Value)
Expand Down
12 changes: 6 additions & 6 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package cadence
import "fmt"

// Unmetered because this function is only used by the client.
func NewValue(value interface{}) (Value, error) {
func NewValue(value any) (Value, error) {
switch v := value.(type) {
case string:
return NewString(v)
Expand All @@ -43,7 +43,7 @@ func NewValue(value interface{}) (Value, error) {
return NewUInt32(v), nil
case uint64:
return NewUInt64(v), nil
case []interface{}:
case []any:
values := make([]Value, len(v))

for i, v := range v {
Expand All @@ -65,7 +65,7 @@ func NewValue(value interface{}) (Value, error) {

// MustConvertValue converts a Go value to an ABI value or panics if the value
// cannot be converted.
func MustConvertValue(value interface{}) Value {
func MustConvertValue(value any) Value {
ret, err := NewValue(value)
if err != nil {
panic(err)
Expand Down Expand Up @@ -119,17 +119,17 @@ func CastToUInt16(value Value) (uint16, error) {
return u, nil
}

func CastToArray(value Value) ([]interface{}, error) {
func CastToArray(value Value) ([]any, error) {
casted, ok := value.(Array)
if !ok {
return nil, fmt.Errorf("%T is not a values.Array", value)
}

goValue := casted.ToGoValue()

u, ok := goValue.([]interface{})
u, ok := goValue.([]any)
if !ok {
return nil, fmt.Errorf("%T is not a []interface{}]", value)
return nil, fmt.Errorf("%T is not a []any]", value)
}
return u, nil
}
Expand Down
10 changes: 5 additions & 5 deletions languageserver/cmd/languageserver/main_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func main() {

js.Global().Set(
startFunctionName,
js.FuncOf(func(this js.Value, args []js.Value) interface{} {
js.FuncOf(func(this js.Value, args []js.Value) any {
id += 1
go start(id)
return id
Expand All @@ -69,7 +69,7 @@ func start(id int) {

global := js.Global()

writeObject := func(obj interface{}) error {
writeObject := func(obj any) error {
// The object / message is sent to the JS environment
// by serializing it to JSON and calling a global function

Expand All @@ -86,7 +86,7 @@ func start(id int) {
return nil
}

readObject := func(v interface{}) (err error) {
readObject := func(v any) (err error) {
// Set up a wait group which allows blocking this function
// until the JS environment calls back

Expand All @@ -102,7 +102,7 @@ func start(id int) {
toServerFunctionName := globalFunctionName(id, "toServer")
global.Set(
toServerFunctionName,
js.FuncOf(func(this js.Value, args []js.Value) interface{} {
js.FuncOf(func(this js.Value, args []js.Value) any {
defer func() {
global.Delete(toServerFunctionName)
wg.Done()
Expand Down Expand Up @@ -147,7 +147,7 @@ func start(id int) {

global.Set(
globalFunctionName(id, "onClientClose"),
js.FuncOf(func(this js.Value, args []js.Value) interface{} {
js.FuncOf(func(this js.Value, args []js.Value) any {
cancel()
return nil
}),
Expand Down
8 changes: 4 additions & 4 deletions languageserver/integration/codelenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func makeActionlessCodelens(title string, lensRange protocol.Range) *protocol.Co
}
}

func makeCodeLens(command string, title string, lensRange protocol.Range, arguments []interface{}) *protocol.CodeLens {
func makeCodeLens(command string, title string, lensRange protocol.Range, arguments []any) *protocol.CodeLens {
return &protocol.CodeLens{
Range: lensRange,
Command: &protocol.Command{
Expand Down Expand Up @@ -294,7 +294,7 @@ func (i *FlowIntegration) scriptCodeLenses(
}

argsJSON, _ := json.Marshal(argumentList)
return makeCodeLens(CommandExecuteScript, title, codelensRange, []interface{}{uri, string(argsJSON)})
return makeCodeLens(CommandExecuteScript, title, codelensRange, []any{uri, string(argsJSON)})
}

func (i *FlowIntegration) transactionCodeLenses(
Expand Down Expand Up @@ -328,7 +328,7 @@ func (i *FlowIntegration) transactionCodeLenses(
CommandSendTransaction,
title,
codelensRange,
[]interface{}{uri, string(argsJSON), accounts},
[]any{uri, string(argsJSON), accounts},
)
}

Expand Down Expand Up @@ -362,5 +362,5 @@ func (i *FlowIntegration) contractCodeLenses(
signer,
)

return makeCodeLens(CommandDeployContract, title, codelensRange, []interface{}{uri, name, resolvedAddress})
return makeCodeLens(CommandDeployContract, title, codelensRange, []any{uri, name, resolvedAddress})
}
18 changes: 9 additions & 9 deletions languageserver/integration/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func makeManagerCode(script string, serviceAddress string) []byte {
// initAccountManager initializes Account manager on service account
//
// No arguments are expected
func (i *FlowIntegration) initAccountManager(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) initAccountManager(conn protocol.Conn, args ...any) (any, error) {
serviceAccount, err := i.state.EmulatorServiceAccount()
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageServiceAccount, err)
Expand Down Expand Up @@ -160,7 +160,7 @@ func (i *FlowIntegration) initAccountManager(conn protocol.Conn, args ...interfa
// There should be exactly 2 arguments:
// * the DocumentURI of the file to submit
// * the arguments, encoded as JSON-CDC
func (i *FlowIntegration) sendTransaction(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) sendTransaction(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 3)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageArguments, err)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (i *FlowIntegration) sendTransaction(conn protocol.Conn, args ...interface{
)
}

signerList := args[2].([]interface{})
signerList := args[2].([]any)
signers := make([]flow.Address, len(signerList))
for i, v := range signerList {
signers[i] = flow.HexToAddress(v.(string))
Expand Down Expand Up @@ -290,7 +290,7 @@ func (i *FlowIntegration) sendTransaction(conn protocol.Conn, args ...interface{
// There should be exactly 2 arguments:
// * the DocumentURI of the file to submit
// * the arguments, encoded as JSON-CDC
func (i *FlowIntegration) executeScript(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) executeScript(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 2)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageArguments, err)
Expand Down Expand Up @@ -356,7 +356,7 @@ func (i *FlowIntegration) executeScript(conn protocol.Conn, args ...interface{})
//
// There should be exactly 1 argument:
// * current state of the emulator represented as byte
func (i *FlowIntegration) changeEmulatorState(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) changeEmulatorState(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 1)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageArguments, err)
Expand All @@ -381,7 +381,7 @@ func (i *FlowIntegration) changeEmulatorState(conn protocol.Conn, args ...interf
// There should be 2 arguments:
// * name of the new active acount
// * address of the new active account
func (i *FlowIntegration) switchActiveAccount(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) switchActiveAccount(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 2)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageArguments, err)
Expand All @@ -406,7 +406,7 @@ func (i *FlowIntegration) switchActiveAccount(conn protocol.Conn, args ...interf
}

// createAccount creates a new account and returns its address.
func (i *FlowIntegration) createAccount(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) createAccount(conn protocol.Conn, args ...any) (any, error) {
address, err := i.createAccountHelper(conn)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageAccountCreate, err)
Expand All @@ -424,7 +424,7 @@ func (i *FlowIntegration) createAccount(conn protocol.Conn, args ...interface{})
//
// There should be exactly 1 argument:
// * number of accounts to be created
func (i *FlowIntegration) createDefaultAccounts(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) createDefaultAccounts(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 1)
if err != nil {
return nil, errorWithMessage(conn, ErrorMessageArguments, err)
Expand Down Expand Up @@ -476,7 +476,7 @@ func (i *FlowIntegration) createDefaultAccounts(conn protocol.Conn, args ...inte
// There should be exactly 2 arguments:
// * the DocumentURI of the file to submit
// * the name of the contract
func (i *FlowIntegration) deployContract(conn protocol.Conn, args ...interface{}) (interface{}, error) {
func (i *FlowIntegration) deployContract(conn protocol.Conn, args ...any) (any, error) {
err := server.CheckCommandArgumentCount(args, 3)
if err != nil {
return flow.Address{}, errorWithMessage(conn, ErrorMessageServiceAccount, err)
Expand Down
4 changes: 2 additions & 2 deletions languageserver/integration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type AccountPrivateKey struct {
//
// Returns an error if any fields are missing or malformed.
//
func configFromInitializationOptions(opts interface{}) (conf Config, err error) {
optsMap, ok := opts.(map[string]interface{})
func configFromInitializationOptions(opts any) (conf Config, err error) {
optsMap, ok := opts.(map[string]any)
if !ok {
return Config{}, errors.New("invalid initialization options")
}
Expand Down
2 changes: 1 addition & 1 deletion languageserver/integration/initialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/spf13/afero"
)

func (i *FlowIntegration) initialize(initializationOptions interface{}) error {
func (i *FlowIntegration) initialize(initializationOptions any) error {
// Parse the configuration options sent from the client
conf, err := configFromInitializationOptions(initializationOptions)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions languageserver/jsonrpc2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (handler *handler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *js
}
}

type Method func(*json.RawMessage) (interface{}, error)
type Method func(*json.RawMessage) (any, error)

type Server struct {
Methods map[string]Method
Expand All @@ -97,11 +97,11 @@ func (server *Server) Start(stream ObjectStream) <-chan struct{} {
return server.conn.DisconnectNotify()
}

func (server *Server) Notify(method string, params interface{}) error {
func (server *Server) Notify(method string, params any) error {
return server.conn.Notify(context.Background(), method, params)
}

func (server *Server) Call(method string, params interface{}) error {
func (server *Server) Call(method string, params any) error {
return server.conn.Call(context.Background(), method, params, nil)
}

Expand Down
Loading

0 comments on commit 113ec7c

Please sign in to comment.