From a93d153392e3926b5483a78a5c361387e66a6cf8 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Thu, 20 Jul 2023 17:38:55 -0700 Subject: [PATCH 01/17] Follow links for validation during storage iteration --- runtime/interpreter/interpreter.go | 138 ++++++---- runtime/storage_test.go | 401 +++++++++++++++++++++++++++++ 2 files changed, 494 insertions(+), 45 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 8e843254d1..19937bcdf5 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -3745,20 +3745,21 @@ func (interpreter *Interpreter) newStorageIterationFunction( }() for key, value := storageIterator.Next(); key != nil && value != nil; key, value = storageIterator.Next() { - staticType := value.StaticType(inter) - // Perform a forced type loading to see if the underlying type is not broken. - // If broken, skip this value from the iteration. - typeError := inter.checkTypeLoading(staticType) - if typeError != nil { - continue - } + staticType := value.StaticType(inter) // TODO: unfortunately, the iterator only returns an atree.Value, not a StorageMapKey identifier := string(key.(StringAtreeValue)) pathValue := NewPathValue(inter, domain, identifier) runtimeType := NewTypeValue(inter, staticType) + // Perform a forced value dereferencing to see if the associated type is not broken. + // If broken, skip this value from the iteration. + valueError := inter.checkValue(address, pathValue, value, staticType) + if valueError != nil { + continue + } + subInvocation := NewInvocation( inter, nil, @@ -3799,14 +3800,20 @@ func (interpreter *Interpreter) newStorageIterationFunction( ) } -func (interpreter *Interpreter) checkTypeLoading(staticType StaticType) (typeError error) { +func (interpreter *Interpreter) checkValue( + address common.Address, + path PathValue, + value Value, + staticType StaticType, +) (valueError error) { + defer func() { if r := recover(); r != nil { rootError := r for { switch err := r.(type) { case errors.UserError, errors.ExternalError: - typeError = err.(error) + valueError = err.(error) return case xerrors.Wrapper: r = err.Unwrap() @@ -3817,8 +3824,36 @@ func (interpreter *Interpreter) checkTypeLoading(staticType StaticType) (typeErr } }() - // Here it is only interested in whether the type can be properly loaded. - _, typeError = interpreter.ConvertStaticToSemaType(staticType) + // Here, the value at the path could be either: + // 1) The actual stored value + // 2) A link to the value at the storage (private/public paths) + // + // Therefore, try to find the final path, and try loading the value. + + // However, borrow type is not statically known. + // So take the borrow type from the value itself + + var borrowedType StaticType + if _, ok := value.(LinkValue); ok { + // Link values always have a `CapabilityStaticType` static type. + borrowedType = staticType.(CapabilityStaticType).BorrowType + } else { + borrowedType = NewReferenceStaticType(interpreter, false, staticType, staticType) + } + + var semaType sema.Type + semaType, valueError = interpreter.ConvertStaticToSemaType(borrowedType) + if valueError != nil { + return valueError + } + + // This is guaranteed to be a reference type, because `borrowedType` is always a reference. + referenceType, ok := semaType.(*sema.ReferenceType) + if !ok { + panic(errors.NewUnreachableError()) + } + + _, valueError = interpreter.checkValueAtPath(address, path, referenceType, EmptyLocationRange) return } @@ -4481,50 +4516,63 @@ func (interpreter *Interpreter) pathCapabilityCheckFunction( panic(errors.NewUnreachableError()) } - target, authorized, err := - interpreter.GetPathCapabilityFinalTarget( - address, - pathValue, - borrowType, - true, - locationRange, - ) + valid, err := interpreter.checkValueAtPath(address, pathValue, borrowType, locationRange) if err != nil { panic(err) } - if target == nil { - return FalseValue - } + return AsBoolValue(valid) + }, + ) +} - switch target := target.(type) { - case AccountCapabilityTarget: - return TrueValue +func (interpreter *Interpreter) checkValueAtPath( + address common.Address, + pathValue PathValue, + borrowType *sema.ReferenceType, + locationRange LocationRange, +) (bool, error) { - case PathCapabilityTarget: - targetPath := PathValue(target) + target, authorized, err := interpreter.GetPathCapabilityFinalTarget( + address, + pathValue, + borrowType, + true, + locationRange, + ) - reference := NewStorageReferenceValue( - interpreter, - authorized, - address, - targetPath, - borrowType.Type, - ) + if err != nil { + return false, err + } - // Attempt to dereference, - // which reads the stored value - // and performs a dynamic type check + if target == nil { + return false, nil + } - return AsBoolValue( - reference.ReferencedValue(interpreter, invocation.LocationRange, false) != nil, - ) + switch target := target.(type) { + case AccountCapabilityTarget: + return true, nil - default: - panic(errors.NewUnreachableError()) - } - }, - ) + case PathCapabilityTarget: + targetPath := PathValue(target) + + reference := NewStorageReferenceValue( + interpreter, + authorized, + address, + targetPath, + borrowType.Type, + ) + + // Attempt to dereference, + // which reads the stored value + // and performs a dynamic type check + + return reference.ReferencedValue(interpreter, locationRange, false) != nil, nil + + default: + panic(errors.NewUnreachableError()) + } } func (interpreter *Interpreter) GetPathCapabilityFinalTarget( diff --git a/runtime/storage_test.go b/runtime/storage_test.go index 93f8c09883..b90f76d35e 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -3790,4 +3790,405 @@ func TestRuntimeStorageIteration(t *testing.T) { ) require.NoError(t, err) }) + + t.Run("broken impl, linked with interface", func(t *testing.T) { + + t.Parallel() + + runtime := newTestInterpreterRuntime() + address := common.MustBytesToAddress([]byte{0x1}) + accountCodes := map[common.Location][]byte{} + ledger := newTestLedger(nil, nil) + nextTransactionLocation := newTransactionLocationGenerator() + contractIsBroken := false + + deployFoo := DeploymentTransaction("Foo", []byte(` + pub contract Foo { + pub resource interface Collection {} + } + `)) + + deployBar := DeploymentTransaction("Bar", []byte(` + import Foo from 0x1 + + pub contract Bar { + pub resource CollectionImpl: Foo.Collection {} + + pub fun getCollection(): @Bar.CollectionImpl { + return <- create Bar.CollectionImpl() + } + } + `)) + + newRuntimeInterface := func() Interface { + return &testRuntimeInterface{ + storage: ledger, + getSigningAccounts: func() ([]Address, error) { + return []Address{address}, nil + }, + resolveLocation: singleIdentifierLocationResolver(t), + updateAccountContractCode: func(location common.AddressLocation, code []byte) error { + accountCodes[location] = code + return nil + }, + getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { + if contractIsBroken && location.Name == "Bar" { + // Contract has a semantic error. i.e: Mismatched types at `bar` function + return []byte(` + import Foo from 0x1 + + pub contract Bar { + pub resource CollectionImpl: Foo.Collection { + pub var mismatch: Int + + init() { + self.mismatch = "hello" + } + } + }`), nil + } + + code = accountCodes[location] + return code, nil + }, + emitEvent: func(event cadence.Event) error { + return nil + }, + } + } + + // Deploy ``Foo` contract + + runtimeInterface := newRuntimeInterface() + + err := runtime.ExecuteTransaction( + Script{ + Source: deployFoo, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Deploy `Bar` contract + + err = runtime.ExecuteTransaction( + Script{ + Source: deployBar, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Store values + + runtimeInterface = newRuntimeInterface() + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Bar from 0x1 + import Foo from 0x1 + + transaction { + prepare(signer: AuthAccount) { + signer.save("Hello, World!", to: /storage/first) + signer.save(<- Bar.getCollection(), to: /storage/second) + + signer.link<&String>(/private/a, target:/storage/first) + signer.link<&AnyResource{Foo.Collection}>(/private/b, target:/storage/second) + + signer.link<&String>(/public/a, target:/storage/first) + signer.link<&AnyResource{Foo.Collection}>(/public/b, target:/storage/second) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Make the `Bar` contract broken. i.e: `Bar.CollectionImpl` type is broken. + contractIsBroken = true + + runtimeInterface = newRuntimeInterface() + + // 1) Iterate through public paths + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + var cap = account.getCapability<&AnyResource{Foo.Collection}>(path) + cap.check() + total = total + 1 + return true + }) + + // Total values iterated should be 1. + // The broken value must be skipped. + assert(total == 1) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // 2) Iterate through private paths + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + var cap = account.getCapability<&AnyResource{Foo.Collection}>(path) + cap.check() + total = total + 1 + return true + }) + + // Total values iterated should be 1. + // The broken value must be skipped. + assert(total == 1) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // 3) Iterate through storage paths + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + account.check<@AnyResource{Foo.Collection}>(from: path) + total = total + 1 + return true + }) + + // Total values iterated should be 1. + // The broken value must be skipped. + assert(total == 1) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + }) + + t.Run("linked with wrong type", func(t *testing.T) { + + t.Parallel() + + test := func(brokenType bool, t *testing.T) { + + runtime := newTestInterpreterRuntime() + address := common.MustBytesToAddress([]byte{0x1}) + accountCodes := map[common.Location][]byte{} + ledger := newTestLedger(nil, nil) + nextTransactionLocation := newTransactionLocationGenerator() + contractIsBroken := false + + deployFoo := DeploymentTransaction("Foo", []byte(` + pub contract Foo { + pub resource interface Collection {} + } + `)) + + deployBar := DeploymentTransaction("Bar", []byte(` + import Foo from 0x1 + + pub contract Bar { + pub resource CollectionImpl: Foo.Collection {} + + pub fun getCollection(): @Bar.CollectionImpl { + return <- create Bar.CollectionImpl() + } + } + `)) + + newRuntimeInterface := func() Interface { + return &testRuntimeInterface{ + storage: ledger, + getSigningAccounts: func() ([]Address, error) { + return []Address{address}, nil + }, + resolveLocation: singleIdentifierLocationResolver(t), + updateAccountContractCode: func(location common.AddressLocation, code []byte) error { + accountCodes[location] = code + return nil + }, + getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { + if contractIsBroken && location.Name == "Bar" { + // Contract has a semantic error. i.e: Mismatched types at `bar` function + return []byte(` + import Foo from 0x1 + + pub contract Bar { + pub resource CollectionImpl: Foo.Collection { + pub var mismatch: Int + + init() { + self.mismatch = "hello" + } + } + }`), nil + } + + code = accountCodes[location] + return code, nil + }, + emitEvent: func(event cadence.Event) error { + return nil + }, + } + } + + // Deploy ``Foo` contract + + runtimeInterface := newRuntimeInterface() + + err := runtime.ExecuteTransaction( + Script{ + Source: deployFoo, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Deploy `Bar` contract + + err = runtime.ExecuteTransaction( + Script{ + Source: deployBar, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Store values + + runtimeInterface = newRuntimeInterface() + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Bar from 0x1 + import Foo from 0x1 + + transaction { + prepare(signer: AuthAccount) { + signer.save("Hello, World!", to: /storage/first) + signer.save(<- Bar.getCollection(), to: /storage/second) + + signer.link<&String>(/private/a, target:/storage/first) + signer.link<&String>(/private/b, target:/storage/second) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Make the `Bar` contract broken. i.e: `Bar.CollectionImpl` type is broken. + contractIsBroken = brokenType + + runtimeInterface = newRuntimeInterface() + + // Iterate through public paths + + // If the type is broken, iterator should only find 1 value. + // Otherwise, it should fin all values (2). + count := 2 + if brokenType { + count = 1 + } + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(fmt.Sprintf(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { + var cap = account.getCapability<&String>(path) + cap.check() + total = total + 1 + return true + }) + + // The broken value must be skipped. + assert(total == %d) + } + } + `, + count, + )), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + } + + t.Run("broken type in storage", func(t *testing.T) { + test(true, t) + }) + + t.Run("valid type in storage", func(t *testing.T) { + test(false, t) + }) + }) } From 5cf6009ff635c4d4574f1b299029532ba8b0f65b Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Fri, 21 Jul 2023 10:52:48 +0300 Subject: [PATCH 02/17] Temporarily remove deprecations for existing capability API --- runtime/sema/authaccount.cdc | 10 ---------- runtime/sema/authaccount.gen.go | 10 ---------- runtime/sema/publicaccount.cdc | 4 ---- runtime/sema/publicaccount.gen.go | 4 ---- 4 files changed, 28 deletions(-) diff --git a/runtime/sema/authaccount.cdc b/runtime/sema/authaccount.cdc index 8617ee2ab6..4814762454 100644 --- a/runtime/sema/authaccount.cdc +++ b/runtime/sema/authaccount.cdc @@ -117,8 +117,6 @@ pub struct AuthAccount { /// The path must be a storage path, i.e., only the domain `storage` is allowed. pub fun check(from: StoragePath): Bool - /// **DEPRECATED**: Instead, use `capabilities.storage.issue`, and `capabilities.publish` if the path is public. - /// /// Creates a capability at the given public or private path, /// which targets the given public, private, or storage path. /// @@ -139,26 +137,18 @@ pub struct AuthAccount { /// and the target value might be moved out after the link has been created. pub fun link(_ newCapabilityPath: CapabilityPath, target: Path): Capability? - /// **DEPRECATED**: Use `capabilities.account.issue` instead. - /// /// Creates a capability at the given public or private path which targets this account. /// /// Returns nil if a link for the given capability path already exists, or the newly created capability if not. pub fun linkAccount(_ newCapabilityPath: PrivatePath): Capability<&AuthAccount>? - /// **DEPRECATED**: Use `capabilities.get` instead. - /// /// Returns the capability at the given private or public path. pub fun getCapability(_ path: CapabilityPath): Capability - /// **DEPRECATED**: Use `capabilities.storage.getController` and `StorageCapabilityController.target()`. - /// /// Returns the target path of the capability at the given public or private path, /// or nil if there exists no capability at the given path. pub fun getLinkTarget(_ path: CapabilityPath): Path? - /// **DEPRECATED**: Use `capabilities.unpublish` instead if the path is public. - /// /// Removes the capability at the given public or private path. pub fun unlink(_ path: CapabilityPath) diff --git a/runtime/sema/authaccount.gen.go b/runtime/sema/authaccount.gen.go index 3425d5deeb..bc39b67733 100644 --- a/runtime/sema/authaccount.gen.go +++ b/runtime/sema/authaccount.gen.go @@ -431,8 +431,6 @@ var AuthAccountTypeLinkFunctionType = &FunctionType{ } const AuthAccountTypeLinkFunctionDocString = ` -**DEPRECATED**: Instead, use ` + "`capabilities.storage.issue`" + `, and ` + "`capabilities.publish`" + ` if the path is public. - Creates a capability at the given public or private path, which targets the given public, private, or storage path. @@ -476,8 +474,6 @@ var AuthAccountTypeLinkAccountFunctionType = &FunctionType{ } const AuthAccountTypeLinkAccountFunctionDocString = ` -**DEPRECATED**: Use ` + "`capabilities.account.issue`" + ` instead. - Creates a capability at the given public or private path which targets this account. Returns nil if a link for the given capability path already exists, or the newly created capability if not. @@ -514,8 +510,6 @@ var AuthAccountTypeGetCapabilityFunctionType = &FunctionType{ } const AuthAccountTypeGetCapabilityFunctionDocString = ` -**DEPRECATED**: Use ` + "`capabilities.get`" + ` instead. - Returns the capability at the given private or public path. ` @@ -537,8 +531,6 @@ var AuthAccountTypeGetLinkTargetFunctionType = &FunctionType{ } const AuthAccountTypeGetLinkTargetFunctionDocString = ` -**DEPRECATED**: Use ` + "`capabilities.storage.getController`" + ` and ` + "`StorageCapabilityController.target()`" + `. - Returns the target path of the capability at the given public or private path, or nil if there exists no capability at the given path. ` @@ -559,8 +551,6 @@ var AuthAccountTypeUnlinkFunctionType = &FunctionType{ } const AuthAccountTypeUnlinkFunctionDocString = ` -**DEPRECATED**: Use ` + "`capabilities.unpublish`" + ` instead if the path is public. - Removes the capability at the given public or private path. ` diff --git a/runtime/sema/publicaccount.cdc b/runtime/sema/publicaccount.cdc index 4e4b8205a0..c59e023af7 100644 --- a/runtime/sema/publicaccount.cdc +++ b/runtime/sema/publicaccount.cdc @@ -28,13 +28,9 @@ pub struct PublicAccount { /// All public paths of this account. pub let publicPaths: [PublicPath] - /// **DEPRECATED**: Use `capabilities.get` instead. - /// /// Returns the capability at the given public path. pub fun getCapability(_ path: PublicPath): Capability - /// **DEPRECATED** - /// /// Returns the target path of the capability at the given public or private path, /// or nil if there exists no capability at the given path. pub fun getLinkTarget(_ path: CapabilityPath): Path? diff --git a/runtime/sema/publicaccount.gen.go b/runtime/sema/publicaccount.gen.go index fc8e2a57ad..1202be2d5c 100644 --- a/runtime/sema/publicaccount.gen.go +++ b/runtime/sema/publicaccount.gen.go @@ -129,8 +129,6 @@ var PublicAccountTypeGetCapabilityFunctionType = &FunctionType{ } const PublicAccountTypeGetCapabilityFunctionDocString = ` -**DEPRECATED**: Use ` + "`capabilities.get`" + ` instead. - Returns the capability at the given public path. ` @@ -152,8 +150,6 @@ var PublicAccountTypeGetLinkTargetFunctionType = &FunctionType{ } const PublicAccountTypeGetLinkTargetFunctionDocString = ` -**DEPRECATED** - Returns the target path of the capability at the given public or private path, or nil if there exists no capability at the given path. ` From ae4c52160bd1f0d7b04adf133247f4caae02670a Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Fri, 21 Jul 2023 14:04:15 -0700 Subject: [PATCH 03/17] Handle wrapped errors returned from FVM --- runtime/interpreter/interpreter.go | 39 ++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 19937bcdf5..904e168a64 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -518,20 +518,8 @@ func (interpreter *Interpreter) InvokeTransaction(index int, arguments ...Value) func (interpreter *Interpreter) RecoverErrors(onError func(error)) { if r := recover(); r != nil { - var err error - // Recover all errors, because interpreter can be directly invoked by FVM. - switch r := r.(type) { - case Error, - errors.ExternalError, - errors.InternalError, - errors.UserError: - err = r.(error) - case error: - err = errors.NewUnexpectedErrorFromCause(r) - default: - err = errors.NewUnexpectedError("%s", r) - } + err := AsCadenceError(r) // if the error is not yet an interpreter error, wrap it if _, ok := err.(Error); !ok { @@ -561,6 +549,31 @@ func (interpreter *Interpreter) RecoverErrors(onError func(error)) { } } +func AsCadenceError(r any) error { + err, isError := r.(error) + if !isError { + return errors.NewUnexpectedError("%s", r) + } + + rootError := err + + for { + switch typedError := err.(type) { + case Error, + errors.ExternalError, + errors.InternalError, + errors.UserError: + return typedError + case xerrors.Wrapper: + err = typedError.Unwrap() + case error: + return errors.NewUnexpectedErrorFromCause(rootError) + default: + return errors.NewUnexpectedErrorFromCause(rootError) + } + } +} + func (interpreter *Interpreter) CallStack() []Invocation { return interpreter.SharedState.callStack.Invocations[:] } From a32ac462d0e44a07dbbc897da8f28acd74a1c2dd Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Fri, 21 Jul 2023 15:03:03 -0700 Subject: [PATCH 04/17] Add test for error mis-clasification --- runtime/interpreter/interpreter.go | 17 ++-- runtime/runtime_test.go | 152 ++++++++++++++++++++++++++++- 2 files changed, 160 insertions(+), 9 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 904e168a64..82b6e92312 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -519,7 +519,7 @@ func (interpreter *Interpreter) InvokeTransaction(index int, arguments ...Value) func (interpreter *Interpreter) RecoverErrors(onError func(error)) { if r := recover(); r != nil { // Recover all errors, because interpreter can be directly invoked by FVM. - err := AsCadenceError(r) + err := asCadenceError(r) // if the error is not yet an interpreter error, wrap it if _, ok := err.(Error); !ok { @@ -549,7 +549,7 @@ func (interpreter *Interpreter) RecoverErrors(onError func(error)) { } } -func AsCadenceError(r any) error { +func asCadenceError(r any) error { err, isError := r.(error) if !isError { return errors.NewUnexpectedError("%s", r) @@ -3838,7 +3838,7 @@ func (interpreter *Interpreter) checkValue( }() // Here, the value at the path could be either: - // 1) The actual stored value + // 1) The actual stored value (storage path) // 2) A link to the value at the storage (private/public paths) // // Therefore, try to find the final path, and try loading the value. @@ -3846,21 +3846,22 @@ func (interpreter *Interpreter) checkValue( // However, borrow type is not statically known. // So take the borrow type from the value itself - var borrowedType StaticType + var borrowType StaticType if _, ok := value.(LinkValue); ok { // Link values always have a `CapabilityStaticType` static type. - borrowedType = staticType.(CapabilityStaticType).BorrowType + borrowType = staticType.(CapabilityStaticType).BorrowType } else { - borrowedType = NewReferenceStaticType(interpreter, false, staticType, staticType) + // Reference type with value's type (i.e. `staticType`) as both the borrow type and the referenced type. + borrowType = NewReferenceStaticType(interpreter, false, staticType, staticType) } var semaType sema.Type - semaType, valueError = interpreter.ConvertStaticToSemaType(borrowedType) + semaType, valueError = interpreter.ConvertStaticToSemaType(borrowType) if valueError != nil { return valueError } - // This is guaranteed to be a reference type, because `borrowedType` is always a reference. + // This is guaranteed to be a reference type, because `borrowType` is always a reference. referenceType, ok := semaType.(*sema.ReferenceType) if !ok { panic(errors.NewUnreachableError()) diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 1f6da1c264..eaa704638c 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -7704,7 +7704,7 @@ func assertRuntimeErrorIsInternalError(t *testing.T, err error) { require.True( t, runtimeErrors.IsInternalError(innerError), - "Expected `UserError`, found `%T`", innerError, + "Expected `InternalError`, found `%T`", innerError, ) } @@ -9000,3 +9000,153 @@ func TestRuntimeReturnDestroyedOptional(t *testing.T) { require.ErrorAs(t, err, &interpreter.DestroyedResourceError{}) } + +func TestRuntimeWrappedErrorHandling(t *testing.T) { + + t.Parallel() + + foo := []byte(` + access(all) contract Foo { + access(all) resource R { + access(all) var x: Int + + init() { + self.x = 0 + } + } + + access(all) fun createR(): @R { + return <-create R() + } + } + `) + + brokenFoo := []byte(` + access(all) contract Foo { + access(all) resource R { + access(all) var x: Int + + init() { + self.x = "hello" + } + } + + access(all) fun createR(): @R { + return <-create R() + } + } + `) + + tx1 := []byte(` + import Foo from 0x1 + + transaction { + prepare(signer: AuthAccount) { + signer.save(<- Foo.createR(), to: /storage/r) + signer.link<&Foo.R>(/private/r, target:/storage/r) + } + } + `) + + tx2 := []byte(` + transaction { + prepare(signer: AuthAccount) { + var cap = signer.getCapability<&AnyStruct>(/private/r) + cap.check() + } + } + `) + + runtime := newTestInterpreterRuntime() + runtime.defaultConfig.AtreeValidationEnabled = false + + address := common.MustBytesToAddress([]byte{0x1}) + + deploy := DeploymentTransaction("Foo", foo) + + var contractCode []byte + var events []cadence.Event + + isContractBroken := false + + runtimeInterface := &testRuntimeInterface{ + getCode: func(_ Location) (bytes []byte, err error) { + return contractCode, nil + }, + storage: newTestLedger(nil, nil), + getSigningAccounts: func() ([]Address, error) { + return []Address{address}, nil + }, + resolveLocation: singleIdentifierLocationResolver(t), + getAccountContractCode: func(_ common.AddressLocation) (code []byte, err error) { + if isContractBroken && contractCode != nil { + return brokenFoo, nil + } + return contractCode, nil + }, + updateAccountContractCode: func(_ common.AddressLocation, code []byte) error { + contractCode = code + return nil + }, + emitEvent: func(event cadence.Event) error { + events = append(events, event) + return nil + }, + getAndSetProgram: func(location Location, load func() (*interpreter.Program, error)) (*interpreter.Program, error) { + program, err := load() + if err == nil { + return program, nil + } + return program, fmt.Errorf("wrapped error: %w", err) + }, + } + + nextTransactionLocation := newTransactionLocationGenerator() + + // Deploy + + err := runtime.ExecuteTransaction( + Script{ + Source: deploy, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Run Tx to save values + + err = runtime.ExecuteTransaction( + Script{ + Source: tx1, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Run Tx to load value. + // Mark the contract is broken + + isContractBroken = true + + err = runtime.ExecuteTransaction( + Script{ + Source: tx2, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + + RequireError(t, err) + + // Returned error MUST be a user error. + // It can NOT be an internal error. + assertRuntimeErrorIsUserError(t, err) +} From abb74027b8101036cc750c2e5ae12a6958953ea2 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 26 Jul 2023 15:56:58 -0700 Subject: [PATCH 05/17] Wrap host env errors with external errors --- runtime/environment.go | 20 +++- runtime/events.go | 2 +- runtime/interpreter/errors.go | 20 ++++ runtime/runtime.go | 1 + runtime/runtime_test.go | 160 ++++++++++++++++++++++++++++++++ runtime/stdlib/account.go | 42 ++++----- runtime/stdlib/block.go | 4 +- runtime/stdlib/hashalgorithm.go | 2 +- runtime/stdlib/log.go | 2 +- runtime/stdlib/publickey.go | 7 +- runtime/stdlib/random.go | 2 +- runtime/storage.go | 4 +- 12 files changed, 234 insertions(+), 32 deletions(-) diff --git a/runtime/environment.go b/runtime/environment.go index 631d8456db..24ce27a85d 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -431,6 +431,10 @@ func (e *interpreterEnvironment) newLocationHandler() sema.LocationHandlerFunc { errors.WrapPanic(func() { res, err = e.runtimeInterface.ResolveLocation(identifiers, location) }) + + if err != nil { + err = interpreter.WrappedExternalError(err) + } return } } @@ -560,6 +564,11 @@ func (e *interpreterEnvironment) getProgram( if panicErr != nil { return nil, panicErr } + + if err != nil { + err = interpreter.WrappedExternalError(err) + } + return }) }) @@ -577,6 +586,11 @@ func (e *interpreterEnvironment) getCode(location common.Location) (code []byte, code, err = e.runtimeInterface.GetCode(location) }) } + + if err != nil { + err = interpreter.WrappedExternalError(err) + } + return } @@ -745,6 +759,10 @@ func (e *interpreterEnvironment) newUUIDHandler() interpreter.UUIDHandlerFunc { errors.WrapPanic(func() { uuid, err = e.runtimeInterface.GenerateUUID() }) + + if err != nil { + err = interpreter.WrappedExternalError(err) + } return } } @@ -941,7 +959,7 @@ func (e *interpreterEnvironment) newOnMeterComputation() interpreter.OnMeterComp err = e.runtimeInterface.MeterComputation(compKind, intensity) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } } } diff --git a/runtime/events.go b/runtime/events.go index 86e01ebe37..4738902bc8 100644 --- a/runtime/events.go +++ b/runtime/events.go @@ -81,6 +81,6 @@ func emitEventFields( err = emitEvent(exportedEvent) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } } diff --git a/runtime/interpreter/errors.go b/runtime/interpreter/errors.go index 1444ef36ae..5b57ea8fe6 100644 --- a/runtime/interpreter/errors.go +++ b/runtime/interpreter/errors.go @@ -20,6 +20,7 @@ package interpreter import ( "fmt" + "runtime" "strings" "github.com/onflow/cadence/runtime/ast" @@ -988,3 +989,22 @@ func (RecursiveTransferError) IsUserError() {} func (RecursiveTransferError) Error() string { return "recursive transfer of value" } + +func WrappedExternalError(err error) error { + switch err := err.(type) { + case + // If the error is a go-runtime error, don't wrap. + // These are crashers. + runtime.Error, + + // If the error is already a cadence error, then avoid redundant wrapping. + errors.InternalError, + errors.UserError, + errors.ExternalError, + Error: + return err + + default: + return errors.NewExternalError(err) + } +} diff --git a/runtime/runtime.go b/runtime/runtime.go index 1ed4f9d6d7..d34514f59f 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -263,6 +263,7 @@ func getWrappedError(recovered any, location Location, codesAndPrograms codesAnd return newError(err, location, codesAndPrograms) } } + func (r *interpreterRuntime) NewScriptExecutor( script Script, context Context, diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 1f6da1c264..81825326cc 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -9000,3 +9000,163 @@ func TestRuntimeReturnDestroyedOptional(t *testing.T) { require.ErrorAs(t, err, &interpreter.DestroyedResourceError{}) } + +func TestRuntimeComputationMeteringError(t *testing.T) { + + t.Parallel() + + runtime := newTestInterpreterRuntime() + + t.Run("regular error returned", func(t *testing.T) { + t.Parallel() + + script := []byte(` + access(all) fun foo() {} + + pub fun main() { + foo() + } + `) + + runtimeInterface := &testRuntimeInterface{ + storage: newTestLedger(nil, nil), + meterComputation: func(compKind common.ComputationKind, intensity uint) error { + return fmt.Errorf("computation limit exceeded") + }, + } + + _, err := runtime.ExecuteScript( + Script{ + Source: script, + }, + Context{ + Interface: runtimeInterface, + Location: common.ScriptLocation{}, + }, + ) + + require.Error(t, err) + + // Returned error MUST be an external error. + // It can NOT be an internal error. + assertRuntimeErrorIsExternalError(t, err) + }) + + t.Run("regular error panicked", func(t *testing.T) { + t.Parallel() + + script := []byte(` + access(all) fun foo() {} + + pub fun main() { + foo() + } + `) + + runtimeInterface := &testRuntimeInterface{ + storage: newTestLedger(nil, nil), + meterComputation: func(compKind common.ComputationKind, intensity uint) error { + panic(fmt.Errorf("computation limit exceeded")) + }, + } + + _, err := runtime.ExecuteScript( + Script{ + Source: script, + }, + Context{ + Interface: runtimeInterface, + Location: common.ScriptLocation{}, + }, + ) + + require.Error(t, err) + + // Returned error MUST be an external error. + // It can NOT be an internal error. + assertRuntimeErrorIsExternalError(t, err) + }) + + t.Run("go runtime error panicked", func(t *testing.T) { + t.Parallel() + + script := []byte(` + access(all) fun foo() {} + + pub fun main() { + foo() + } + `) + + runtimeInterface := &testRuntimeInterface{ + storage: newTestLedger(nil, nil), + meterComputation: func(compKind common.ComputationKind, intensity uint) error { + // Cause a runtime error + var x any = "hello" + _ = x.(int) + return nil + }, + } + + _, err := runtime.ExecuteScript( + Script{ + Source: script, + }, + Context{ + Interface: runtimeInterface, + Location: common.ScriptLocation{}, + }, + ) + + require.Error(t, err) + + // Returned error MUST be an internal error. + assertRuntimeErrorIsInternalError(t, err) + }) + + t.Run("go runtime error returned", func(t *testing.T) { + t.Parallel() + + script := []byte(` + access(all) fun foo() {} + + pub fun main() { + foo() + } + `) + + runtimeInterface := &testRuntimeInterface{ + storage: newTestLedger(nil, nil), + meterComputation: func(compKind common.ComputationKind, intensity uint) (err error) { + // Cause a runtime error. Catch it and return. + var x any = "hello" + defer func() { + if r := recover(); r != nil { + if r, ok := r.(error); ok { + err = r + } + } + }() + + _ = x.(int) + + return + }, + } + + _, err := runtime.ExecuteScript( + Script{ + Source: script, + }, + Context{ + Interface: runtimeInterface, + Location: common.ScriptLocation{}, + }, + ) + + require.Error(t, err) + + // Returned error MUST be an internal error. + assertRuntimeErrorIsInternalError(t, err) + }) +} diff --git a/runtime/stdlib/account.go b/runtime/stdlib/account.go index cc01bb4c23..55825d75ad 100644 --- a/runtime/stdlib/account.go +++ b/runtime/stdlib/account.go @@ -128,7 +128,7 @@ func NewAuthAccountConstructor(creator AccountCreator) StandardLibraryValue { address, err = creator.CreateAccount(payerAddress) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -345,7 +345,7 @@ func newAccountBalanceGetFunction( balance, err = provider.GetAccountBalance(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -374,7 +374,7 @@ func newAccountAvailableBalanceGetFunction( balance, err = provider.GetAccountAvailableBalance(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -413,7 +413,7 @@ func newStorageUsedGetFunction( capacity, err = provider.GetStorageUsed(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return capacity }, @@ -452,7 +452,7 @@ func newStorageCapacityGetFunction( capacity, err = provider.GetStorageCapacity(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return capacity }, @@ -498,7 +498,7 @@ func newAddPublicKeyFunction( err = handler.AddEncodedAccountKey(address, publicKey) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } handler.EmitEvent( @@ -546,7 +546,7 @@ func newRemovePublicKeyFunction( publicKey, err = handler.RevokeEncodedAccountKey(address, index.ToInt(invocation.LocationRange)) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } inter := invocation.Interpreter @@ -620,7 +620,7 @@ func newAccountKeysAddFunction( accountKey, err = handler.AddAccountKey(address, publicKey, hashAlgo, weight) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } handler.EmitEvent( @@ -691,7 +691,7 @@ func newAccountKeysGetFunction( }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // Here it is expected the host function to return a nil key, if a key is not found at the given index. @@ -774,7 +774,7 @@ func newAccountKeysForEachFunction( }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } var accountKey *AccountKey @@ -784,7 +784,7 @@ func newAccountKeysForEachFunction( accountKey, err = provider.GetAccountKey(address, int(index)) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // Here it is expected the host function to return a nil key, if a key is not found at the given index. @@ -838,7 +838,7 @@ func newAccountKeysCountGetter( if err != nil { // The provider might not be able to fetch the number of account keys // e.g. when the account does not exist - panic(err) + panic(interpreter.WrappedExternalError(err)) } return count @@ -882,7 +882,7 @@ func newAccountKeysRevokeFunction( accountKey, err = handler.RevokeAccountKey(address, index) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // Here it is expected the host function to return a nil key, if a key is not found at the given index. @@ -1250,7 +1250,7 @@ func newAccountContractsGetNamesFunction( names, err = provider.GetAccountContractNames(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } values := make([]interpreter.Value, len(names)) @@ -1315,7 +1315,7 @@ func newAccountContractsGetFunction( code, err = provider.GetAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if len(code) > 0 { @@ -1381,7 +1381,7 @@ func newAccountContractsBorrowFunction( code, err = handler.GetAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if len(code) == 0 { return interpreter.Nil @@ -1821,7 +1821,7 @@ func updateAccountContractCode( err = handler.UpdateAccountContractCode(location, code) }) if err != nil { - return err + return interpreter.WrappedExternalError(err) } if createContract { @@ -1978,7 +1978,7 @@ func newAuthAccountContractsRemoveFunction( code, err = handler.GetAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // Only remove the contract code, remove the contract value, and emit an event, @@ -2006,7 +2006,7 @@ func newAuthAccountContractsRemoveFunction( err = handler.RemoveAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // NOTE: the contract recording function delays the write @@ -2534,7 +2534,7 @@ func issueStorageCapabilityController( capabilityID, err = idGenerator.GenerateAccountID(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if capabilityID == 0 { panic(errors.NewUnexpectedError("invalid zero account ID")) @@ -2616,7 +2616,7 @@ func issueAccountCapabilityController( capabilityID, err = idGenerator.GenerateAccountID(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if capabilityID == 0 { panic(errors.NewUnexpectedError("invalid zero account ID")) diff --git a/runtime/stdlib/block.go b/runtime/stdlib/block.go index 19c9a5cab6..c2d77ef022 100644 --- a/runtime/stdlib/block.go +++ b/runtime/stdlib/block.go @@ -180,7 +180,7 @@ func getBlockAtHeight( block, exists, err = provider.GetBlockAtHeight(height) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return block, exists @@ -205,7 +205,7 @@ func NewGetCurrentBlockFunction(provider CurrentBlockProvider) StandardLibraryVa height, err = provider.GetCurrentBlockHeight() }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } block, exists := getBlockAtHeight( diff --git a/runtime/stdlib/hashalgorithm.go b/runtime/stdlib/hashalgorithm.go index 0e36b20b4b..74a428123f 100644 --- a/runtime/stdlib/hashalgorithm.go +++ b/runtime/stdlib/hashalgorithm.go @@ -155,7 +155,7 @@ func hash( result, err = hasher.Hash(data, tag, hashAlgorithm) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return interpreter.ByteSliceToByteArrayValue(inter, result) } diff --git a/runtime/stdlib/log.go b/runtime/stdlib/log.go index c794c2e07d..3e5a92ad2c 100644 --- a/runtime/stdlib/log.go +++ b/runtime/stdlib/log.go @@ -64,7 +64,7 @@ func NewLogFunction(logger Logger) StandardLibraryValue { err = logger.ProgramLog(message) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return interpreter.Void diff --git a/runtime/stdlib/publickey.go b/runtime/stdlib/publickey.go index 6ea9ae53d4..29d4bad749 100644 --- a/runtime/stdlib/publickey.go +++ b/runtime/stdlib/publickey.go @@ -67,6 +67,9 @@ func newPublicKeyValidationHandler(validator PublicKeyValidator) interpreter.Pub errors.WrapPanic(func() { err = validator.ValidatePublicKey(publicKey) }) + if err != nil { + err = interpreter.WrappedExternalError(err) + } return err } } @@ -290,7 +293,7 @@ func newPublicKeyVerifySignatureFunction( }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return interpreter.AsBoolValue(valid) @@ -343,7 +346,7 @@ func newPublicKeyVerifyPoPFunction( valid, err = verifier.BLSVerifyPOP(publicKey, signature) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return interpreter.AsBoolValue(valid) }, diff --git a/runtime/stdlib/random.go b/runtime/stdlib/random.go index 7967fe28c4..c37b0abf44 100644 --- a/runtime/stdlib/random.go +++ b/runtime/stdlib/random.go @@ -59,7 +59,7 @@ func NewUnsafeRandomFunction(generator UnsafeRandomGenerator) StandardLibraryVal rand, err = generator.UnsafeRandom() }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return rand }, diff --git a/runtime/storage.go b/runtime/storage.go index 53ee07c2e4..dd4618a747 100644 --- a/runtime/storage.go +++ b/runtime/storage.go @@ -102,7 +102,7 @@ func (s *Storage) GetStorageMap( data, err = s.Ledger.GetValue(key.Address[:], []byte(key.Key)) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } dataLength := len(data) @@ -258,7 +258,7 @@ func (s *Storage) commitNewStorageMaps() error { ) }) if err != nil { - return err + return interpreter.WrappedExternalError(err) } } From fe2ba6312d4434c2e45b0118202c8a17b50a230d Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Thu, 27 Jul 2023 09:15:35 -0700 Subject: [PATCH 06/17] Update go.cap --- go.cap | 1 + 1 file changed, 1 insertion(+) diff --git a/go.cap b/go.cap index 34dba49742..bb341c9fa6 100644 --- a/go.cap +++ b/go.cap @@ -10,3 +10,4 @@ github.com/stretchr/testify/require (network) github.com/texttheater/golang-levenshtein/levenshtein (file) github.com/zeebo/blake3/internal/consts (file) golang.org/x/xerrors (runtime) +github.com/onflow/cadence/runtime/interpreter (runtime) From e5694e7d6d5549f4653e906c78e32d68128eba18 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Tue, 1 Aug 2023 12:03:34 -0700 Subject: [PATCH 07/17] Pass down the location range --- runtime/interpreter/interpreter.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 82b6e92312..31e1b6dcdf 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -3766,9 +3766,16 @@ func (interpreter *Interpreter) newStorageIterationFunction( pathValue := NewPathValue(inter, domain, identifier) runtimeType := NewTypeValue(inter, staticType) - // Perform a forced value dereferencing to see if the associated type is not broken. + // Perform a forced value de-referencing to see if the associated type is not broken. // If broken, skip this value from the iteration. - valueError := inter.checkValue(address, pathValue, value, staticType) + valueError := inter.checkValue( + address, + pathValue, + value, + staticType, + invocation.LocationRange, + ) + if valueError != nil { continue } @@ -3818,6 +3825,7 @@ func (interpreter *Interpreter) checkValue( path PathValue, value Value, staticType StaticType, + locationRange LocationRange, ) (valueError error) { defer func() { @@ -3867,7 +3875,7 @@ func (interpreter *Interpreter) checkValue( panic(errors.NewUnreachableError()) } - _, valueError = interpreter.checkValueAtPath(address, path, referenceType, EmptyLocationRange) + _, valueError = interpreter.checkValueAtPath(address, path, referenceType, locationRange) return } From 13d25132ee67be2fa4c6bfe0970a96eb8d36680a Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Wed, 2 Aug 2023 09:48:11 -0700 Subject: [PATCH 08/17] Fix error on reference creation with invalid type --- runtime/sema/check_reference_expression.go | 4 ++- runtime/tests/checker/reference_test.go | 37 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/runtime/sema/check_reference_expression.go b/runtime/sema/check_reference_expression.go index 8ae9906317..68d8c20e72 100644 --- a/runtime/sema/check_reference_expression.go +++ b/runtime/sema/check_reference_expression.go @@ -92,7 +92,9 @@ func (checker *Checker) VisitReferenceExpression(referenceExpression *ast.Refere // If the reference type was a non-optional type, // check that the referenced expression does not have an optional type - if _, ok := actualType.(*OptionalType); ok != isOpt { + // Do not report an error if the `expectedLeftType` is unknown + + if _, ok := actualType.(*OptionalType); ok != isOpt && expectedLeftType != nil { checker.report(&TypeMismatchError{ ExpectedType: expectedLeftType, ActualType: actualType, diff --git a/runtime/tests/checker/reference_test.go b/runtime/tests/checker/reference_test.go index 4b4fb18632..0c328a1a1f 100644 --- a/runtime/tests/checker/reference_test.go +++ b/runtime/tests/checker/reference_test.go @@ -1304,3 +1304,40 @@ func TestCheckReferenceTypeImplicitConformance(t *testing.T) { require.IsType(t, &sema.TypeMismatchError{}, errs[0]) }) } + +func TestCheckReferenceCreationWithInvalidType(t *testing.T) { + + t.Parallel() + + t.Run("invalid reference type", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + let foo: AnyStruct? = nil + let x = &foo as &Foo + `) + + errs := RequireCheckerErrors(t, err, 1) + + var notDeclaredError *sema.NotDeclaredError + require.ErrorAs(t, errs[0], ¬DeclaredError) + }) + + t.Run("valid non-reference type", func(t *testing.T) { + + t.Parallel() + + _, err := ParseAndCheck(t, ` + struct Foo {} + + let foo: AnyStruct? = nil + let x = &foo as Foo + `) + + errs := RequireCheckerErrors(t, err, 1) + + var nonReferenceTypeReferenceError *sema.NonReferenceTypeReferenceError + require.ErrorAs(t, errs[0], &nonReferenceTypeReferenceError) + }) +} From 48e73aa1a5be8a75f683df02a1b1a5448c4843da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 2 Aug 2023 17:06:56 -0700 Subject: [PATCH 09/17] remove unused code --- runtime/interpreter/location.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/runtime/interpreter/location.go b/runtime/interpreter/location.go index dc465a8a91..4186c84c3e 100644 --- a/runtime/interpreter/location.go +++ b/runtime/interpreter/location.go @@ -23,14 +23,6 @@ import ( "github.com/onflow/cadence/runtime/common" ) -// LocationPosition defines a position in the source of the import tree. -// The Location defines the script within the import tree, the Position -// defines the row/colum within the source of that script. -type LocationPosition struct { - Location common.Location - Position ast.Position -} - // LocationRange defines a range in the source of the import tree. // The Position defines the script within the import tree, the Range // defines the start/end position within the source of that script. From c373e388ad713e004d34c2519a39c945a43d96ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 2 Aug 2023 17:08:25 -0700 Subject: [PATCH 10/17] provide location ranges --- runtime/interpreter/value.go | 3502 +++++++++++++++++++++------------- runtime/literal.go | 3 +- runtime/parser/errors.go | 1 + 3 files changed, 2152 insertions(+), 1354 deletions(-) diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go index 6b11e3737a..1049ab84ea 100644 --- a/runtime/interpreter/value.go +++ b/runtime/interpreter/value.go @@ -258,9 +258,13 @@ type ValueIterator interface { func safeAdd(a, b int, locationRange LocationRange) int { // INT32-C if (b > 0) && (a > (goMaxInt - b)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (b < 0) && (a < (goMinInt - b)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return a + b } @@ -271,24 +275,32 @@ func safeMul(a, b int, locationRange LocationRange) int { if b > 0 { // positive * positive = positive. overflow? if a > (goMaxInt / b) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } else { // positive * negative = negative. underflow? if b < (goMinInt / a) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } } else { if b > 0 { // negative * positive = negative. underflow? if a < (goMinInt / b) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } else { // negative * negative = positive. overflow? if (a != 0) && (b < (goMaxInt / a)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } } @@ -674,7 +686,7 @@ func (v BoolValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool { return bool(v) == bool(otherBool) } -func (v BoolValue) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v BoolValue) Less(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -683,7 +695,7 @@ func (v BoolValue) Less(interpreter *Interpreter, other ComparableValue, locatio return !v && o } -func (v BoolValue) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v BoolValue) LessEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -692,7 +704,7 @@ func (v BoolValue) LessEqual(interpreter *Interpreter, other ComparableValue, lo return !v || o } -func (v BoolValue) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v BoolValue) Greater(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -701,7 +713,7 @@ func (v BoolValue) Greater(interpreter *Interpreter, other ComparableValue, loca return v && !o } -func (v BoolValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v BoolValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { o, ok := other.(BoolValue) if !ok { panic(errors.NewUnreachableError()) @@ -868,7 +880,7 @@ func (v CharacterValue) Equal(_ *Interpreter, _ LocationRange, other Value) bool return v.NormalForm() == otherChar.NormalForm() } -func (v CharacterValue) Less(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v CharacterValue) Less(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -876,7 +888,7 @@ func (v CharacterValue) Less(interpreter *Interpreter, other ComparableValue, lo return v.NormalForm() < otherChar.NormalForm() } -func (v CharacterValue) LessEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v CharacterValue) LessEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -884,7 +896,7 @@ func (v CharacterValue) LessEqual(interpreter *Interpreter, other ComparableValu return v.NormalForm() <= otherChar.NormalForm() } -func (v CharacterValue) Greater(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v CharacterValue) Greater(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -892,7 +904,7 @@ func (v CharacterValue) Greater(interpreter *Interpreter, other ComparableValue, return v.NormalForm() > otherChar.NormalForm() } -func (v CharacterValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, locationRange LocationRange) BoolValue { +func (v CharacterValue) GreaterEqual(_ *Interpreter, other ComparableValue, _ LocationRange) BoolValue { otherChar, ok := other.(CharacterValue) if !ok { panic(errors.NewUnreachableError()) @@ -1099,9 +1111,10 @@ func (v *StringValue) Less(interpreter *Interpreter, other ComparableValue, loca otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -1112,9 +1125,10 @@ func (v *StringValue) LessEqual(interpreter *Interpreter, other ComparableValue, otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -1125,9 +1139,10 @@ func (v *StringValue) Greater(interpreter *Interpreter, other ComparableValue, l otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -1138,9 +1153,10 @@ func (v *StringValue) GreaterEqual(interpreter *Interpreter, other ComparableVal otherString, ok := other.(*StringValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3176,7 +3192,9 @@ func (IntValue) IsImportable(_ *Interpreter) bool { func (v IntValue) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -3208,7 +3226,7 @@ func (v IntValue) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferences return v.String() } -func (v IntValue) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { +func (v IntValue) Negate(interpreter *Interpreter, _ LocationRange) NumberValue { return NewIntValueFromBigInt( interpreter, common.NewNegateBigIntMemoryUsage(v.BigInt), @@ -3222,9 +3240,10 @@ func (v IntValue) Plus(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3243,9 +3262,10 @@ func (v IntValue) SaturatingPlus(interpreter *Interpreter, other NumberValue, lo r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -3257,9 +3277,10 @@ func (v IntValue) Minus(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3278,9 +3299,10 @@ func (v IntValue) SaturatingMinus(interpreter *Interpreter, other NumberValue, l r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -3292,9 +3314,10 @@ func (v IntValue) Mod(interpreter *Interpreter, other NumberValue, locationRange o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3305,7 +3328,9 @@ func (v IntValue) Mod(interpreter *Interpreter, other NumberValue, locationRange res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Rem(v.BigInt, o.BigInt) }, @@ -3316,9 +3341,10 @@ func (v IntValue) Mul(interpreter *Interpreter, other NumberValue, locationRange o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3337,9 +3363,10 @@ func (v IntValue) SaturatingMul(interpreter *Interpreter, other NumberValue, loc r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -3351,9 +3378,10 @@ func (v IntValue) Div(interpreter *Interpreter, other NumberValue, locationRange o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3364,7 +3392,9 @@ func (v IntValue) Div(interpreter *Interpreter, other NumberValue, locationRange res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -3376,9 +3406,10 @@ func (v IntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, loc r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -3390,9 +3421,10 @@ func (v IntValue) Less(interpreter *Interpreter, other ComparableValue, location o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3404,9 +3436,10 @@ func (v IntValue) LessEqual(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3418,9 +3451,10 @@ func (v IntValue) Greater(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3433,9 +3467,10 @@ func (v IntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3475,9 +3510,10 @@ func (v IntValue) BitwiseOr(interpreter *Interpreter, other IntegerValue, locati o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3495,9 +3531,10 @@ func (v IntValue) BitwiseXor(interpreter *Interpreter, other IntegerValue, locat o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3515,9 +3552,10 @@ func (v IntValue) BitwiseAnd(interpreter *Interpreter, other IntegerValue, locat o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3535,18 +3573,23 @@ func (v IntValue) BitwiseLeftShift(interpreter *Interpreter, other IntegerValue, o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewIntValueFromBigInt( @@ -3563,18 +3606,23 @@ func (v IntValue) BitwiseRightShift(interpreter *Interpreter, other IntegerValue o, ok := other.(IntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewIntValueFromBigInt( @@ -3721,14 +3769,16 @@ func (v Int8Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReference return v.String() } -func (v Int8Value) ToInt(locationRange LocationRange) int { +func (v Int8Value) ToInt(_ LocationRange) int { return int(v) } func (v Int8Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt8 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int8 { @@ -3742,17 +3792,22 @@ func (v Int8Value) Plus(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v > (math.MaxInt8 - o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v < (math.MinInt8 - o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int8 { @@ -3766,9 +3821,10 @@ func (v Int8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3789,17 +3845,22 @@ func (v Int8Value) Minus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v < (math.MinInt8 + o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v > (math.MaxInt8 + o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int8 { @@ -3813,9 +3874,10 @@ func (v Int8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3836,15 +3898,18 @@ func (v Int8Value) Mod(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() int8 { @@ -3858,9 +3923,10 @@ func (v Int8Value) Mul(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3869,24 +3935,32 @@ func (v Int8Value) Mul(interpreter *Interpreter, other NumberValue, locationRang if o > 0 { // positive * positive = positive. overflow? if v > (math.MaxInt8 / o) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } else { // positive * negative = negative. underflow? if o < (math.MinInt8 / v) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } } else { if o > 0 { // negative * positive = negative. underflow? if v < (math.MinInt8 / o) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } else { // negative * negative = positive. overflow? if (v != 0) && (o < (math.MaxInt8 / v)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } } @@ -3902,9 +3976,10 @@ func (v Int8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, lo o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3946,18 +4021,23 @@ func (v Int8Value) Div(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt8) && (o == -1) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int8 { @@ -3971,9 +4051,10 @@ func (v Int8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -3981,7 +4062,9 @@ func (v Int8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt8) && (o == -1) { return math.MaxInt8 } @@ -3995,9 +4078,10 @@ func (v Int8Value) Less(interpreter *Interpreter, other ComparableValue, locatio o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4008,9 +4092,10 @@ func (v Int8Value) LessEqual(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4021,9 +4106,10 @@ func (v Int8Value) Greater(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4034,9 +4120,10 @@ func (v Int8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4067,18 +4154,26 @@ func ConvertInt8(memoryGauge common.MemoryGauge, value Value, locationRange Loca case BigNumberValue: v := value.ToBigInt(memoryGauge) if v.Cmp(sema.Int8TypeMaxInt) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int8TypeMinInt) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int8(v.Int64()) case NumberValue: v := value.ToInt(locationRange) if v > math.MaxInt8 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v < math.MinInt8 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int8(v) @@ -4094,9 +4189,10 @@ func (v Int8Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, locat o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4111,9 +4207,10 @@ func (v Int8Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4128,9 +4225,10 @@ func (v Int8Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4145,9 +4243,10 @@ func (v Int8Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValue o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4162,9 +4261,10 @@ func (v Int8Value) BitwiseRightShift(interpreter *Interpreter, other IntegerValu o, ok := other.(Int8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4310,14 +4410,16 @@ func (v Int16Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v Int16Value) ToInt(locationRange LocationRange) int { +func (v Int16Value) ToInt(_ LocationRange) int { return int(v) } func (v Int16Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt16 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int16 { @@ -4331,17 +4433,22 @@ func (v Int16Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v > (math.MaxInt16 - o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v < (math.MinInt16 - o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int16 { @@ -4355,9 +4462,10 @@ func (v Int16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4378,17 +4486,22 @@ func (v Int16Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v < (math.MinInt16 + o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v > (math.MaxInt16 + o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int16 { @@ -4402,9 +4515,10 @@ func (v Int16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4425,15 +4539,18 @@ func (v Int16Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() int16 { @@ -4447,9 +4564,10 @@ func (v Int16Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4458,24 +4576,32 @@ func (v Int16Value) Mul(interpreter *Interpreter, other NumberValue, locationRan if o > 0 { // positive * positive = positive. overflow? if v > (math.MaxInt16 / o) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } else { // positive * negative = negative. underflow? if o < (math.MinInt16 / v) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } } else { if o > 0 { // negative * positive = negative. underflow? if v < (math.MinInt16 / o) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } else { // negative * negative = positive. overflow? if (v != 0) && (o < (math.MaxInt16 / v)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } } @@ -4491,9 +4617,10 @@ func (v Int16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4534,18 +4661,23 @@ func (v Int16Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt16) && (o == -1) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int16 { @@ -4559,9 +4691,10 @@ func (v Int16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4569,7 +4702,9 @@ func (v Int16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt16) && (o == -1) { return math.MaxInt16 } @@ -4583,9 +4718,10 @@ func (v Int16Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4596,9 +4732,10 @@ func (v Int16Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4609,9 +4746,10 @@ func (v Int16Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4622,9 +4760,10 @@ func (v Int16Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4655,18 +4794,26 @@ func ConvertInt16(memoryGauge common.MemoryGauge, value Value, locationRange Loc case BigNumberValue: v := value.ToBigInt(memoryGauge) if v.Cmp(sema.Int16TypeMaxInt) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int16TypeMinInt) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int16(v.Int64()) case NumberValue: v := value.ToInt(locationRange) if v > math.MaxInt16 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v < math.MinInt16 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int16(v) @@ -4682,9 +4829,10 @@ func (v Int16Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4699,9 +4847,10 @@ func (v Int16Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4716,9 +4865,10 @@ func (v Int16Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4733,9 +4883,10 @@ func (v Int16Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValu o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4750,9 +4901,10 @@ func (v Int16Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Int16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4900,14 +5052,16 @@ func (v Int32Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v Int32Value) ToInt(locationRange LocationRange) int { +func (v Int32Value) ToInt(_ LocationRange) int { return int(v) } func (v Int32Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt32 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int32 { @@ -4921,17 +5075,22 @@ func (v Int32Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v > (math.MaxInt32 - o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v < (math.MinInt32 - o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int32 { @@ -4945,9 +5104,10 @@ func (v Int32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -4968,17 +5128,22 @@ func (v Int32Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v < (math.MinInt32 + o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v > (math.MaxInt32 + o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int32 { @@ -4992,9 +5157,10 @@ func (v Int32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5015,15 +5181,18 @@ func (v Int32Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() int32 { @@ -5037,9 +5206,10 @@ func (v Int32Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5048,24 +5218,32 @@ func (v Int32Value) Mul(interpreter *Interpreter, other NumberValue, locationRan if o > 0 { // positive * positive = positive. overflow? if v > (math.MaxInt32 / o) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } else { // positive * negative = negative. underflow? if o < (math.MinInt32 / v) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } } else { if o > 0 { // negative * positive = negative. underflow? if v < (math.MinInt32 / o) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } else { // negative * negative = positive. overflow? if (v != 0) && (o < (math.MaxInt32 / v)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } } @@ -5081,9 +5259,10 @@ func (v Int32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5124,18 +5303,23 @@ func (v Int32Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt32) && (o == -1) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int32 { @@ -5149,9 +5333,10 @@ func (v Int32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5159,7 +5344,9 @@ func (v Int32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt32) && (o == -1) { return math.MaxInt32 } @@ -5174,9 +5361,10 @@ func (v Int32Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5187,9 +5375,10 @@ func (v Int32Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5200,9 +5389,10 @@ func (v Int32Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5213,9 +5403,10 @@ func (v Int32Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5245,18 +5436,26 @@ func ConvertInt32(memoryGauge common.MemoryGauge, value Value, locationRange Loc case BigNumberValue: v := value.ToBigInt(memoryGauge) if v.Cmp(sema.Int32TypeMaxInt) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int32TypeMinInt) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int32(v.Int64()) case NumberValue: v := value.ToInt(locationRange) if v > math.MaxInt32 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v < math.MinInt32 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int32(v) @@ -5272,9 +5471,10 @@ func (v Int32Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5289,9 +5489,10 @@ func (v Int32Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5306,9 +5507,10 @@ func (v Int32Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5323,9 +5525,10 @@ func (v Int32Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValu o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5340,9 +5543,10 @@ func (v Int32Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Int32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5488,14 +5692,16 @@ func (v Int64Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v Int64Value) ToInt(locationRange LocationRange) int { +func (v Int64Value) ToInt(_ LocationRange) int { return int(v) } func (v Int64Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int64 { @@ -5508,9 +5714,13 @@ func (v Int64Value) Negate(interpreter *Interpreter, locationRange LocationRange func safeAddInt64(a, b int64, locationRange LocationRange) int64 { // INT32-C if (b > 0) && (a > (math.MaxInt64 - b)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (b < 0) && (a < (math.MinInt64 - b)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return a + b } @@ -5519,9 +5729,10 @@ func (v Int64Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5536,9 +5747,10 @@ func (v Int64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5559,17 +5771,22 @@ func (v Int64Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT32-C if (o > 0) && (v < (math.MinInt64 + o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v > (math.MaxInt64 + o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int64 { @@ -5583,9 +5800,10 @@ func (v Int64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5606,15 +5824,18 @@ func (v Int64Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() int64 { @@ -5628,9 +5849,10 @@ func (v Int64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5639,24 +5861,32 @@ func (v Int64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan if o > 0 { // positive * positive = positive. overflow? if v > (math.MaxInt64 / o) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } else { // positive * negative = negative. underflow? if o < (math.MinInt64 / v) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } } else { if o > 0 { // negative * positive = negative. underflow? if v < (math.MinInt64 / o) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } } else { // negative * negative = positive. overflow? if (v != 0) && (o < (math.MaxInt64 / v)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } } } @@ -5672,9 +5902,10 @@ func (v Int64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5715,18 +5946,23 @@ func (v Int64Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt64) && (o == -1) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int64 { @@ -5740,9 +5976,10 @@ func (v Int64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5750,7 +5987,9 @@ func (v Int64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l // INT33-C // https://golang.org/ref/spec#Integer_operators if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } else if (v == math.MinInt64) && (o == -1) { return math.MaxInt64 } @@ -5764,9 +6003,10 @@ func (v Int64Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5777,9 +6017,10 @@ func (v Int64Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5790,9 +6031,10 @@ func (v Int64Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5804,9 +6046,10 @@ func (v Int64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5836,9 +6079,13 @@ func ConvertInt64(memoryGauge common.MemoryGauge, value Value, locationRange Loc case BigNumberValue: v := value.ToBigInt(memoryGauge) if v.Cmp(sema.Int64TypeMaxInt) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int64TypeMinInt) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v.Int64() @@ -5858,9 +6105,10 @@ func (v Int64Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5875,9 +6123,10 @@ func (v Int64Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5892,9 +6141,10 @@ func (v Int64Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5909,9 +6159,10 @@ func (v Int64Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValu o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -5926,9 +6177,10 @@ func (v Int64Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Int64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6075,7 +6327,9 @@ func (Int128Value) IsImportable(_ *Interpreter) bool { func (v Int128Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -6113,7 +6367,9 @@ func (v Int128Value) Negate(interpreter *Interpreter, locationRange LocationRang // ... // } if v.BigInt.Cmp(sema.Int128TypeMinIntBig) == 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() *big.Int { @@ -6127,9 +6383,10 @@ func (v Int128Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6149,9 +6406,13 @@ func (v Int128Value) Plus(interpreter *Interpreter, other NumberValue, locationR res := new(big.Int) res.Add(v.BigInt, o.BigInt) if res.Cmp(sema.Int128TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -6164,9 +6425,10 @@ func (v Int128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6201,9 +6463,10 @@ func (v Int128Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6223,9 +6486,13 @@ func (v Int128Value) Minus(interpreter *Interpreter, other NumberValue, location res := new(big.Int) res.Sub(v.BigInt, o.BigInt) if res.Cmp(sema.Int128TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -6238,9 +6505,10 @@ func (v Int128Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6275,9 +6543,10 @@ func (v Int128Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6285,7 +6554,9 @@ func (v Int128Value) Mod(interpreter *Interpreter, other NumberValue, locationRa res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.Rem(v.BigInt, o.BigInt) @@ -6299,9 +6570,10 @@ func (v Int128Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6309,9 +6581,13 @@ func (v Int128Value) Mul(interpreter *Interpreter, other NumberValue, locationRa res := new(big.Int) res.Mul(v.BigInt, o.BigInt) if res.Cmp(sema.Int128TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -6324,9 +6600,10 @@ func (v Int128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6349,9 +6626,10 @@ func (v Int128Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6364,11 +6642,15 @@ func (v Int128Value) Div(interpreter *Interpreter, other NumberValue, locationRa // ... // } if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.SetInt64(-1) if (v.BigInt.Cmp(sema.Int128TypeMinIntBig) == 0) && (o.BigInt.Cmp(res) == 0) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } res.Div(v.BigInt, o.BigInt) @@ -6382,9 +6664,10 @@ func (v Int128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6397,7 +6680,9 @@ func (v Int128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, // ... // } if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.SetInt64(-1) if (v.BigInt.Cmp(sema.Int128TypeMinIntBig) == 0) && (o.BigInt.Cmp(res) == 0) { @@ -6415,9 +6700,10 @@ func (v Int128Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6429,9 +6715,10 @@ func (v Int128Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6443,9 +6730,10 @@ func (v Int128Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6457,9 +6745,10 @@ func (v Int128Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6511,9 +6800,13 @@ func ConvertInt128(memoryGauge common.MemoryGauge, value Value, locationRange Lo } if v.Cmp(sema.Int128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int128TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v @@ -6526,9 +6819,10 @@ func (v Int128Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6545,9 +6839,10 @@ func (v Int128Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6564,9 +6859,10 @@ func (v Int128Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6583,17 +6879,22 @@ func (v Int128Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() *big.Int { @@ -6609,17 +6910,22 @@ func (v Int128Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Int128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() *big.Int { @@ -6765,7 +7071,9 @@ func (Int256Value) IsImportable(_ *Interpreter) bool { func (v Int256Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -6803,7 +7111,9 @@ func (v Int256Value) Negate(interpreter *Interpreter, locationRange LocationRang // ... // } if v.BigInt.Cmp(sema.Int256TypeMinIntBig) == 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() *big.Int { @@ -6817,9 +7127,10 @@ func (v Int256Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6839,9 +7150,13 @@ func (v Int256Value) Plus(interpreter *Interpreter, other NumberValue, locationR res := new(big.Int) res.Add(v.BigInt, o.BigInt) if res.Cmp(sema.Int256TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -6854,9 +7169,10 @@ func (v Int256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6891,9 +7207,10 @@ func (v Int256Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6913,9 +7230,13 @@ func (v Int256Value) Minus(interpreter *Interpreter, other NumberValue, location res := new(big.Int) res.Sub(v.BigInt, o.BigInt) if res.Cmp(sema.Int256TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -6928,9 +7249,10 @@ func (v Int256Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6965,9 +7287,10 @@ func (v Int256Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6975,7 +7298,9 @@ func (v Int256Value) Mod(interpreter *Interpreter, other NumberValue, locationRa res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.Rem(v.BigInt, o.BigInt) @@ -6989,9 +7314,10 @@ func (v Int256Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -6999,9 +7325,13 @@ func (v Int256Value) Mul(interpreter *Interpreter, other NumberValue, locationRa res := new(big.Int) res.Mul(v.BigInt, o.BigInt) if res.Cmp(sema.Int256TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if res.Cmp(sema.Int256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res @@ -7014,9 +7344,10 @@ func (v Int256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7039,9 +7370,10 @@ func (v Int256Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7054,11 +7386,15 @@ func (v Int256Value) Div(interpreter *Interpreter, other NumberValue, locationRa // ... // } if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.SetInt64(-1) if (v.BigInt.Cmp(sema.Int256TypeMinIntBig) == 0) && (o.BigInt.Cmp(res) == 0) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } res.Div(v.BigInt, o.BigInt) return res @@ -7071,9 +7407,10 @@ func (v Int256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7086,7 +7423,9 @@ func (v Int256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, // ... // } if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.SetInt64(-1) if (v.BigInt.Cmp(sema.Int256TypeMinIntBig) == 0) && (o.BigInt.Cmp(res) == 0) { @@ -7103,9 +7442,10 @@ func (v Int256Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7117,9 +7457,10 @@ func (v Int256Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7131,9 +7472,10 @@ func (v Int256Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7145,9 +7487,10 @@ func (v Int256Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7199,9 +7542,13 @@ func ConvertInt256(memoryGauge common.MemoryGauge, value Value, locationRange Lo } if v.Cmp(sema.Int256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Cmp(sema.Int256TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v @@ -7214,9 +7561,10 @@ func (v Int256Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7233,9 +7581,10 @@ func (v Int256Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7252,9 +7601,10 @@ func (v Int256Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7271,19 +7621,24 @@ func (v Int256Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } valueGetter := func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } res.Lsh(v.BigInt, uint(o.BigInt.Uint64())) @@ -7297,19 +7652,24 @@ func (v Int256Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Int256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } valueGetter := func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } res.Rsh(v.BigInt, uint(o.BigInt.Uint64())) return res @@ -7439,7 +7799,9 @@ func ConvertUInt(memoryGauge common.MemoryGauge, value Value, locationRange Loca func() *big.Int { v := value.ToBigInt(memoryGauge) if v.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v }, @@ -7448,7 +7810,9 @@ func ConvertUInt(memoryGauge common.MemoryGauge, value Value, locationRange Loca case NumberValue: v := value.ToInt(locationRange) if v < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return NewUIntValueFromUint64( memoryGauge, @@ -7489,7 +7853,9 @@ func (v UIntValue) IsImportable(_ *Interpreter) bool { func (v UIntValue) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -7529,9 +7895,10 @@ func (v UIntValue) Plus(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7550,9 +7917,10 @@ func (v UIntValue) SaturatingPlus(interpreter *Interpreter, other NumberValue, l r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -7564,9 +7932,10 @@ func (v UIntValue) Minus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7578,7 +7947,9 @@ func (v UIntValue) Minus(interpreter *Interpreter, other NumberValue, locationRa res.Sub(v.BigInt, o.BigInt) // INT30-C if res.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return res }, @@ -7589,9 +7960,10 @@ func (v UIntValue) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7614,9 +7986,10 @@ func (v UIntValue) Mod(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7627,7 +8000,9 @@ func (v UIntValue) Mod(interpreter *Interpreter, other NumberValue, locationRang res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } res.Rem(v.BigInt, o.BigInt) return res @@ -7639,9 +8014,10 @@ func (v UIntValue) Mul(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7660,9 +8036,10 @@ func (v UIntValue) SaturatingMul(interpreter *Interpreter, other NumberValue, lo r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -7674,9 +8051,10 @@ func (v UIntValue) Div(interpreter *Interpreter, other NumberValue, locationRang o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7687,7 +8065,9 @@ func (v UIntValue) Div(interpreter *Interpreter, other NumberValue, locationRang res := new(big.Int) // INT33-C if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -7699,9 +8079,10 @@ func (v UIntValue) SaturatingDiv(interpreter *Interpreter, other NumberValue, lo r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -7713,9 +8094,10 @@ func (v UIntValue) Less(interpreter *Interpreter, other ComparableValue, locatio o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7727,9 +8109,10 @@ func (v UIntValue) LessEqual(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7741,9 +8124,10 @@ func (v UIntValue) Greater(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7755,9 +8139,10 @@ func (v UIntValue) GreaterEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7797,9 +8182,10 @@ func (v UIntValue) BitwiseOr(interpreter *Interpreter, other IntegerValue, locat o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7817,9 +8203,10 @@ func (v UIntValue) BitwiseXor(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7837,9 +8224,10 @@ func (v UIntValue) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -7857,18 +8245,23 @@ func (v UIntValue) BitwiseLeftShift(interpreter *Interpreter, other IntegerValue o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewUIntValueFromBigInt( @@ -7886,17 +8279,22 @@ func (v UIntValue) BitwiseRightShift(interpreter *Interpreter, other IntegerValu o, ok := other.(UIntValue) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewUIntValueFromBigInt( @@ -8042,7 +8440,7 @@ func (v UInt8Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v UInt8Value) ToInt(locationRange LocationRange) int { +func (v UInt8Value) ToInt(_ LocationRange) int { return int(v) } @@ -8054,9 +8452,10 @@ func (v UInt8Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8064,7 +8463,9 @@ func (v UInt8Value) Plus(interpreter *Interpreter, other NumberValue, locationRa sum := v + o // INT30-C if sum < v { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint8(sum) }) @@ -8074,9 +8475,10 @@ func (v UInt8Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8094,9 +8496,10 @@ func (v UInt8Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8106,7 +8509,9 @@ func (v UInt8Value) Minus(interpreter *Interpreter, other NumberValue, locationR diff := v - o // INT30-C if diff > v { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint8(diff) }, @@ -8117,9 +8522,10 @@ func (v UInt8Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8140,9 +8546,10 @@ func (v UInt8Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8150,7 +8557,9 @@ func (v UInt8Value) Mod(interpreter *Interpreter, other NumberValue, locationRan interpreter, func() uint8 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint8(v % o) }, @@ -8161,9 +8570,10 @@ func (v UInt8Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8172,7 +8582,9 @@ func (v UInt8Value) Mul(interpreter *Interpreter, other NumberValue, locationRan func() uint8 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint8 / o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint8(v * o) }, @@ -8183,9 +8595,10 @@ func (v UInt8Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8205,9 +8618,10 @@ func (v UInt8Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8215,7 +8629,9 @@ func (v UInt8Value) Div(interpreter *Interpreter, other NumberValue, locationRan interpreter, func() uint8 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint8(v / o) }, @@ -8227,9 +8643,10 @@ func (v UInt8Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -8241,9 +8658,10 @@ func (v UInt8Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8254,9 +8672,10 @@ func (v UInt8Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8267,9 +8686,10 @@ func (v UInt8Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8280,9 +8700,10 @@ func (v UInt8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8317,18 +8738,26 @@ func ConvertUnsigned[T Unsigned]( case BigNumberValue: v := value.ToBigInt(memoryGauge) if v.Cmp(maxBigNumber) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return T(v.Int64()) case NumberValue: v := value.ToInt(locationRange) if maxNumber > 0 && v > maxNumber { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return T(v) @@ -8373,9 +8802,10 @@ func (v UInt8Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8391,9 +8821,10 @@ func (v UInt8Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8409,9 +8840,10 @@ func (v UInt8Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8427,9 +8859,10 @@ func (v UInt8Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValu o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8445,9 +8878,10 @@ func (v UInt8Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVal o, ok := other.(UInt8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8592,7 +9026,7 @@ func (v UInt16Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen return v.String() } -func (v UInt16Value) ToInt(locationRange LocationRange) int { +func (v UInt16Value) ToInt(_ LocationRange) int { return int(v) } func (v UInt16Value) Negate(*Interpreter, LocationRange) NumberValue { @@ -8603,9 +9037,10 @@ func (v UInt16Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8615,7 +9050,9 @@ func (v UInt16Value) Plus(interpreter *Interpreter, other NumberValue, locationR sum := v + o // INT30-C if sum < v { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint16(sum) }, @@ -8626,9 +9063,10 @@ func (v UInt16Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8649,9 +9087,10 @@ func (v UInt16Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8661,7 +9100,9 @@ func (v UInt16Value) Minus(interpreter *Interpreter, other NumberValue, location diff := v - o // INT30-C if diff > v { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint16(diff) }, @@ -8672,9 +9113,10 @@ func (v UInt16Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8695,9 +9137,10 @@ func (v UInt16Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8705,7 +9148,9 @@ func (v UInt16Value) Mod(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint16 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint16(v % o) }, @@ -8716,9 +9161,10 @@ func (v UInt16Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8727,7 +9173,9 @@ func (v UInt16Value) Mul(interpreter *Interpreter, other NumberValue, locationRa func() uint16 { // INT30-C if (v > 0) && (o > 0) && (v > (math.MaxUint16 / o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint16(v * o) }, @@ -8738,9 +9186,10 @@ func (v UInt16Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8760,9 +9209,10 @@ func (v UInt16Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8770,7 +9220,9 @@ func (v UInt16Value) Div(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint16 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint16(v / o) }, @@ -8782,9 +9234,10 @@ func (v UInt16Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -8796,9 +9249,10 @@ func (v UInt16Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8809,9 +9263,10 @@ func (v UInt16Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8822,9 +9277,10 @@ func (v UInt16Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8835,9 +9291,10 @@ func (v UInt16Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8880,9 +9337,10 @@ func (v UInt16Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8898,9 +9356,10 @@ func (v UInt16Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8916,9 +9375,10 @@ func (v UInt16Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8934,9 +9394,10 @@ func (v UInt16Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -8952,9 +9413,10 @@ func (v UInt16Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(UInt16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9105,7 +9567,7 @@ func (v UInt32Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen return v.String() } -func (v UInt32Value) ToInt(locationRange LocationRange) int { +func (v UInt32Value) ToInt(_ LocationRange) int { return int(v) } @@ -9117,9 +9579,10 @@ func (v UInt32Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9129,7 +9592,9 @@ func (v UInt32Value) Plus(interpreter *Interpreter, other NumberValue, locationR sum := v + o // INT30-C if sum < v { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint32(sum) }, @@ -9140,9 +9605,10 @@ func (v UInt32Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9163,9 +9629,10 @@ func (v UInt32Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9175,7 +9642,9 @@ func (v UInt32Value) Minus(interpreter *Interpreter, other NumberValue, location diff := v - o // INT30-C if diff > v { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint32(diff) }, @@ -9186,9 +9655,10 @@ func (v UInt32Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9209,9 +9679,10 @@ func (v UInt32Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9219,7 +9690,9 @@ func (v UInt32Value) Mod(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint32 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint32(v % o) }, @@ -9230,9 +9703,10 @@ func (v UInt32Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9240,7 +9714,9 @@ func (v UInt32Value) Mul(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint32 { if (v > 0) && (o > 0) && (v > (math.MaxUint32 / o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint32(v * o) }, @@ -9251,9 +9727,10 @@ func (v UInt32Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9274,9 +9751,10 @@ func (v UInt32Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9284,7 +9762,9 @@ func (v UInt32Value) Div(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint32 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint32(v / o) }, @@ -9296,9 +9776,10 @@ func (v UInt32Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -9310,9 +9791,10 @@ func (v UInt32Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9323,9 +9805,10 @@ func (v UInt32Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9336,9 +9819,10 @@ func (v UInt32Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9349,9 +9833,10 @@ func (v UInt32Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9394,9 +9879,10 @@ func (v UInt32Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9412,9 +9898,10 @@ func (v UInt32Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9430,9 +9917,10 @@ func (v UInt32Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9448,9 +9936,10 @@ func (v UInt32Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9466,9 +9955,10 @@ func (v UInt32Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(UInt32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9627,7 +10117,9 @@ func (v UInt64Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen func (v UInt64Value) ToInt(locationRange LocationRange) int { if v > math.MaxInt64 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v) } @@ -9655,7 +10147,9 @@ func safeAddUint64(a, b uint64, locationRange LocationRange) uint64 { sum := a + b // INT30-C if sum < a { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return sum } @@ -9664,9 +10158,10 @@ func (v UInt64Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9682,9 +10177,10 @@ func (v UInt64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9705,9 +10201,10 @@ func (v UInt64Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9717,7 +10214,9 @@ func (v UInt64Value) Minus(interpreter *Interpreter, other NumberValue, location diff := v - o // INT30-C if diff > v { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint64(diff) }, @@ -9728,9 +10227,10 @@ func (v UInt64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9751,9 +10251,10 @@ func (v UInt64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9761,7 +10262,9 @@ func (v UInt64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint64 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint64(v % o) }, @@ -9772,9 +10275,10 @@ func (v UInt64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9782,7 +10286,9 @@ func (v UInt64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint64 { if (v > 0) && (o > 0) && (v > (math.MaxUint64 / o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return uint64(v * o) }, @@ -9793,9 +10299,10 @@ func (v UInt64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9815,9 +10322,10 @@ func (v UInt64Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9825,7 +10333,9 @@ func (v UInt64Value) Div(interpreter *Interpreter, other NumberValue, locationRa interpreter, func() uint64 { if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return uint64(v / o) }, @@ -9837,9 +10347,10 @@ func (v UInt64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -9851,9 +10362,10 @@ func (v UInt64Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9864,9 +10376,10 @@ func (v UInt64Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9877,9 +10390,10 @@ func (v UInt64Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9890,9 +10404,10 @@ func (v UInt64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9935,9 +10450,10 @@ func (v UInt64Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9953,9 +10469,10 @@ func (v UInt64Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9971,9 +10488,10 @@ func (v UInt64Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -9989,9 +10507,10 @@ func (v UInt64Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10007,9 +10526,10 @@ func (v UInt64Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(UInt64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10161,7 +10681,9 @@ func (UInt128Value) IsImportable(_ *Interpreter) bool { func (v UInt128Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -10201,9 +10723,10 @@ func (v UInt128Value) Plus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10223,7 +10746,9 @@ func (v UInt128Value) Plus(interpreter *Interpreter, other NumberValue, location // } // if sum.Cmp(sema.UInt128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return sum }, @@ -10234,9 +10759,10 @@ func (v UInt128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10267,9 +10793,10 @@ func (v UInt128Value) Minus(interpreter *Interpreter, other NumberValue, locatio o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10289,7 +10816,9 @@ func (v UInt128Value) Minus(interpreter *Interpreter, other NumberValue, locatio // } // if diff.Cmp(sema.UInt128TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return diff }, @@ -10300,9 +10829,10 @@ func (v UInt128Value) SaturatingMinus(interpreter *Interpreter, other NumberValu o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10333,9 +10863,10 @@ func (v UInt128Value) Mod(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10344,7 +10875,9 @@ func (v UInt128Value) Mod(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Rem(v.BigInt, o.BigInt) }, @@ -10355,9 +10888,10 @@ func (v UInt128Value) Mul(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10367,7 +10901,9 @@ func (v UInt128Value) Mul(interpreter *Interpreter, other NumberValue, locationR res := new(big.Int) res.Mul(v.BigInt, o.BigInt) if res.Cmp(sema.UInt128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res }, @@ -10378,9 +10914,10 @@ func (v UInt128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10401,9 +10938,10 @@ func (v UInt128Value) Div(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10412,7 +10950,9 @@ func (v UInt128Value) Div(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -10425,9 +10965,10 @@ func (v UInt128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -10439,9 +10980,10 @@ func (v UInt128Value) Less(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10453,9 +10995,10 @@ func (v UInt128Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10467,9 +11010,10 @@ func (v UInt128Value) Greater(interpreter *Interpreter, other ComparableValue, l o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10481,9 +11025,10 @@ func (v UInt128Value) GreaterEqual(interpreter *Interpreter, other ComparableVal o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10538,9 +11083,13 @@ func ConvertUInt128(memoryGauge common.MemoryGauge, value Value, locationRange L } if v.Cmp(sema.UInt128TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v @@ -10552,9 +11101,10 @@ func (v UInt128Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10571,9 +11121,10 @@ func (v UInt128Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, l o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10590,9 +11141,10 @@ func (v UInt128Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, l o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10610,9 +11162,10 @@ func (v UInt128Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10621,10 +11174,14 @@ func (v UInt128Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Lsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -10635,9 +11192,10 @@ func (v UInt128Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV o, ok := other.(UInt128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10646,10 +11204,14 @@ func (v UInt128Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Rsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -10794,7 +11356,9 @@ func (UInt256Value) IsImportable(_ *Interpreter) bool { func (v UInt256Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) @@ -10835,9 +11399,10 @@ func (v UInt256Value) Plus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10857,7 +11422,9 @@ func (v UInt256Value) Plus(interpreter *Interpreter, other NumberValue, location // } // if sum.Cmp(sema.UInt256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return sum }, @@ -10869,9 +11436,10 @@ func (v UInt256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10902,9 +11470,10 @@ func (v UInt256Value) Minus(interpreter *Interpreter, other NumberValue, locatio o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10924,7 +11493,9 @@ func (v UInt256Value) Minus(interpreter *Interpreter, other NumberValue, locatio // } // if diff.Cmp(sema.UInt256TypeMinIntBig) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return diff }, @@ -10935,9 +11506,10 @@ func (v UInt256Value) SaturatingMinus(interpreter *Interpreter, other NumberValu o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10969,9 +11541,10 @@ func (v UInt256Value) Mod(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -10980,7 +11553,9 @@ func (v UInt256Value) Mod(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Rem(v.BigInt, o.BigInt) }, @@ -10991,9 +11566,10 @@ func (v UInt256Value) Mul(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11003,7 +11579,9 @@ func (v UInt256Value) Mul(interpreter *Interpreter, other NumberValue, locationR res := new(big.Int) res.Mul(v.BigInt, o.BigInt) if res.Cmp(sema.UInt256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res }, @@ -11014,9 +11592,10 @@ func (v UInt256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11037,9 +11616,10 @@ func (v UInt256Value) Div(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11048,7 +11628,9 @@ func (v UInt256Value) Div(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -11060,9 +11642,10 @@ func (v UInt256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -11074,9 +11657,10 @@ func (v UInt256Value) Less(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11088,9 +11672,10 @@ func (v UInt256Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11102,9 +11687,10 @@ func (v UInt256Value) Greater(interpreter *Interpreter, other ComparableValue, l o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11116,9 +11702,10 @@ func (v UInt256Value) GreaterEqual(interpreter *Interpreter, other ComparableVal o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11172,9 +11759,13 @@ func ConvertUInt256(memoryGauge common.MemoryGauge, value Value, locationRange L } if v.Cmp(sema.UInt256TypeMaxIntBig) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if v.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return v @@ -11186,9 +11777,10 @@ func (v UInt256Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11205,9 +11797,10 @@ func (v UInt256Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, l o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11224,9 +11817,10 @@ func (v UInt256Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, l o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11243,9 +11837,10 @@ func (v UInt256Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11254,10 +11849,14 @@ func (v UInt256Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Lsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -11268,9 +11867,10 @@ func (v UInt256Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV o, ok := other.(UInt256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11279,10 +11879,14 @@ func (v UInt256Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Rsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -11427,7 +12031,7 @@ func (v Word8Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v Word8Value) ToInt(locationRange LocationRange) int { +func (v Word8Value) ToInt(_ LocationRange) int { return int(v) } @@ -11439,9 +12043,10 @@ func (v Word8Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11460,9 +12065,10 @@ func (v Word8Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11481,14 +12087,17 @@ func (v Word8Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint8 { @@ -11502,9 +12111,10 @@ func (v Word8Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11523,14 +12133,17 @@ func (v Word8Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint8 { @@ -11548,9 +12161,10 @@ func (v Word8Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11561,9 +12175,10 @@ func (v Word8Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11574,9 +12189,10 @@ func (v Word8Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11587,9 +12203,10 @@ func (v Word8Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11626,9 +12243,10 @@ func (v Word8Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loca o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11643,9 +12261,10 @@ func (v Word8Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11660,9 +12279,10 @@ func (v Word8Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11677,9 +12297,10 @@ func (v Word8Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerValu o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11694,9 +12315,10 @@ func (v Word8Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Word8Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11846,7 +12468,7 @@ func (v Word16Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen return v.String() } -func (v Word16Value) ToInt(locationRange LocationRange) int { +func (v Word16Value) ToInt(_ LocationRange) int { return int(v) } func (v Word16Value) Negate(*Interpreter, LocationRange) NumberValue { @@ -11857,9 +12479,10 @@ func (v Word16Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11878,9 +12501,10 @@ func (v Word16Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11899,14 +12523,17 @@ func (v Word16Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint16 { @@ -11920,9 +12547,10 @@ func (v Word16Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11941,14 +12569,17 @@ func (v Word16Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint16 { @@ -11966,9 +12597,10 @@ func (v Word16Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11979,9 +12611,10 @@ func (v Word16Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -11992,9 +12625,10 @@ func (v Word16Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12005,9 +12639,10 @@ func (v Word16Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12044,9 +12679,10 @@ func (v Word16Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12061,9 +12697,10 @@ func (v Word16Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12078,9 +12715,10 @@ func (v Word16Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12095,9 +12733,10 @@ func (v Word16Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12112,9 +12751,10 @@ func (v Word16Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Word16Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12266,7 +12906,7 @@ func (v Word32Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen return v.String() } -func (v Word32Value) ToInt(locationRange LocationRange) int { +func (v Word32Value) ToInt(_ LocationRange) int { return int(v) } @@ -12278,9 +12918,10 @@ func (v Word32Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12299,9 +12940,10 @@ func (v Word32Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12320,14 +12962,17 @@ func (v Word32Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint32 { @@ -12341,9 +12986,10 @@ func (v Word32Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12362,14 +13008,17 @@ func (v Word32Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint32 { @@ -12387,9 +13036,10 @@ func (v Word32Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12400,9 +13050,10 @@ func (v Word32Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12413,9 +13064,10 @@ func (v Word32Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12426,9 +13078,10 @@ func (v Word32Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12465,9 +13118,10 @@ func (v Word32Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12482,9 +13136,10 @@ func (v Word32Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12499,9 +13154,10 @@ func (v Word32Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12516,9 +13172,10 @@ func (v Word32Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12533,9 +13190,10 @@ func (v Word32Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Word32Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12695,7 +13353,9 @@ func (v Word64Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen func (v Word64Value) ToInt(locationRange LocationRange) int { if v > math.MaxInt64 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v) } @@ -12723,9 +13383,10 @@ func (v Word64Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12744,9 +13405,10 @@ func (v Word64Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12765,14 +13427,17 @@ func (v Word64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint64 { @@ -12786,9 +13451,10 @@ func (v Word64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12807,14 +13473,17 @@ func (v Word64Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } if o == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } valueGetter := func() uint64 { @@ -12832,9 +13501,10 @@ func (v Word64Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12845,9 +13515,10 @@ func (v Word64Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12858,9 +13529,10 @@ func (v Word64Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12871,9 +13543,10 @@ func (v Word64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12910,9 +13583,10 @@ func (v Word64Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, loc o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12927,9 +13601,10 @@ func (v Word64Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12944,9 +13619,10 @@ func (v Word64Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12961,9 +13637,10 @@ func (v Word64Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVal o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -12978,9 +13655,10 @@ func (v Word64Value) BitwiseRightShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Word64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13131,7 +13809,9 @@ func (Word128Value) IsImportable(_ *Interpreter) bool { func (v Word128Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -13171,9 +13851,10 @@ func (v Word128Value) Plus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13204,7 +13885,7 @@ func (v Word128Value) Plus(interpreter *Interpreter, other NumberValue, location ) } -func (v Word128Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) SaturatingPlus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13212,9 +13893,10 @@ func (v Word128Value) Minus(interpreter *Interpreter, other NumberValue, locatio o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13245,7 +13927,7 @@ func (v Word128Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v Word128Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) SaturatingMinus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13253,9 +13935,10 @@ func (v Word128Value) Mod(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13264,7 +13947,9 @@ func (v Word128Value) Mod(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Rem(v.BigInt, o.BigInt) }, @@ -13275,9 +13960,10 @@ func (v Word128Value) Mul(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13294,7 +13980,7 @@ func (v Word128Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word128Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) SaturatingMul(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13302,9 +13988,10 @@ func (v Word128Value) Div(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13313,7 +14000,9 @@ func (v Word128Value) Div(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -13321,7 +14010,7 @@ func (v Word128Value) Div(interpreter *Interpreter, other NumberValue, locationR } -func (v Word128Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word128Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13329,9 +14018,10 @@ func (v Word128Value) Less(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13343,9 +14033,10 @@ func (v Word128Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13357,9 +14048,10 @@ func (v Word128Value) Greater(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13371,9 +14063,10 @@ func (v Word128Value) GreaterEqual(interpreter *Interpreter, other ComparableVal o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13442,9 +14135,10 @@ func (v Word128Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13461,9 +14155,10 @@ func (v Word128Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, l o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13480,9 +14175,10 @@ func (v Word128Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, l o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13500,9 +14196,10 @@ func (v Word128Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Word128Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13511,10 +14208,14 @@ func (v Word128Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Lsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -13536,10 +14237,14 @@ func (v Word128Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Rsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -13684,7 +14389,9 @@ func (Word256Value) IsImportable(_ *Interpreter) bool { func (v Word256Value) ToInt(locationRange LocationRange) int { if !v.BigInt.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return int(v.BigInt.Int64()) } @@ -13724,9 +14431,10 @@ func (v Word256Value) Plus(interpreter *Interpreter, other NumberValue, location o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13757,7 +14465,7 @@ func (v Word256Value) Plus(interpreter *Interpreter, other NumberValue, location ) } -func (v Word256Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) SaturatingPlus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13765,9 +14473,10 @@ func (v Word256Value) Minus(interpreter *Interpreter, other NumberValue, locatio o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13798,7 +14507,7 @@ func (v Word256Value) Minus(interpreter *Interpreter, other NumberValue, locatio ) } -func (v Word256Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) SaturatingMinus(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13806,9 +14515,10 @@ func (v Word256Value) Mod(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13817,7 +14527,9 @@ func (v Word256Value) Mod(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Rem(v.BigInt, o.BigInt) }, @@ -13828,9 +14540,10 @@ func (v Word256Value) Mul(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13847,7 +14560,7 @@ func (v Word256Value) Mul(interpreter *Interpreter, other NumberValue, locationR ) } -func (v Word256Value) SaturatingMul(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) SaturatingMul(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13855,9 +14568,10 @@ func (v Word256Value) Div(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13866,7 +14580,9 @@ func (v Word256Value) Div(interpreter *Interpreter, other NumberValue, locationR func() *big.Int { res := new(big.Int) if o.BigInt.Cmp(res) == 0 { - panic(DivisionByZeroError{LocationRange: locationRange}) + panic(DivisionByZeroError{ + LocationRange: locationRange, + }) } return res.Div(v.BigInt, o.BigInt) }, @@ -13874,7 +14590,7 @@ func (v Word256Value) Div(interpreter *Interpreter, other NumberValue, locationR } -func (v Word256Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, locationRange LocationRange) NumberValue { +func (v Word256Value) SaturatingDiv(_ *Interpreter, _ NumberValue, _ LocationRange) NumberValue { panic(errors.NewUnreachableError()) } @@ -13882,9 +14598,10 @@ func (v Word256Value) Less(interpreter *Interpreter, other ComparableValue, loca o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13896,9 +14613,10 @@ func (v Word256Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13910,9 +14628,10 @@ func (v Word256Value) Greater(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13924,9 +14643,10 @@ func (v Word256Value) GreaterEqual(interpreter *Interpreter, other ComparableVal o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -13995,9 +14715,10 @@ func (v Word256Value) BitwiseOr(interpreter *Interpreter, other IntegerValue, lo o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseOr, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseOr, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14014,9 +14735,10 @@ func (v Word256Value) BitwiseXor(interpreter *Interpreter, other IntegerValue, l o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseXor, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseXor, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14033,9 +14755,10 @@ func (v Word256Value) BitwiseAnd(interpreter *Interpreter, other IntegerValue, l o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseAnd, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseAnd, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14053,9 +14776,10 @@ func (v Word256Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseLeftShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseLeftShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14064,10 +14788,14 @@ func (v Word256Value) BitwiseLeftShift(interpreter *Interpreter, other IntegerVa func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Lsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -14078,9 +14806,10 @@ func (v Word256Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV o, ok := other.(Word256Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationBitwiseRightShift, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationBitwiseRightShift, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14089,10 +14818,14 @@ func (v Word256Value) BitwiseRightShift(interpreter *Interpreter, other IntegerV func() *big.Int { res := new(big.Int) if o.BigInt.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if !o.BigInt.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return res.Rsh(v.BigInt, uint(o.BigInt.Uint64())) }, @@ -14199,11 +14932,15 @@ func NewFix64ValueWithInteger(gauge common.MemoryGauge, constructor func() int64 func NewUnmeteredFix64ValueWithInteger(integer int64, locationRange LocationRange) Fix64Value { if integer < sema.Fix64TypeMinInt { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } if integer > sema.Fix64TypeMaxInt { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewUnmeteredFix64Value(integer * sema.Fix64Factor) @@ -14263,14 +15000,16 @@ func (v Fix64Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferenc return v.String() } -func (v Fix64Value) ToInt(locationRange LocationRange) int { +func (v Fix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } func (v Fix64Value) Negate(interpreter *Interpreter, locationRange LocationRange) NumberValue { // INT32-C if v == math.MinInt64 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } valueGetter := func() int64 { @@ -14284,9 +15023,10 @@ func (v Fix64Value) Plus(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14301,9 +15041,10 @@ func (v Fix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14324,18 +15065,23 @@ func (v Fix64Value) Minus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } valueGetter := func() int64 { // INT32-C if (o > 0) && (v < (math.MinInt64 + o)) { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } else if (o < 0) && (v > (math.MaxInt64 + o)) { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return int64(v - o) @@ -14348,9 +15094,10 @@ func (v Fix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue, o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14374,9 +15121,10 @@ func (v Fix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14388,9 +15136,13 @@ func (v Fix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRan result.Div(result, sema.Fix64FactorBig) if result.Cmp(minInt64Big) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if result.Cmp(maxInt64Big) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return result.Int64() @@ -14403,9 +15155,10 @@ func (v Fix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, l o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14432,9 +15185,10 @@ func (v Fix64Value) Div(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14446,9 +15200,13 @@ func (v Fix64Value) Div(interpreter *Interpreter, other NumberValue, locationRan result.Div(result, b) if result.Cmp(minInt64Big) < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } else if result.Cmp(maxInt64Big) > 0 { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return result.Int64() @@ -14461,9 +15219,10 @@ func (v Fix64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, l o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14490,9 +15249,10 @@ func (v Fix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRan o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14500,9 +15260,10 @@ func (v Fix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRan quotient, ok := v.Div(interpreter, o, locationRange).(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14524,9 +15285,10 @@ func (v Fix64Value) Less(interpreter *Interpreter, other ComparableValue, locati o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14537,9 +15299,10 @@ func (v Fix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, l o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14550,9 +15313,10 @@ func (v Fix64Value) Greater(interpreter *Interpreter, other ComparableValue, loc o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14563,9 +15327,10 @@ func (v Fix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValue o, ok := other.(Fix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14596,7 +15361,9 @@ func ConvertFix64(memoryGauge common.MemoryGauge, value Value, locationRange Loc case UFix64Value: if value > Fix64MaxValue { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewFix64Value( memoryGauge, @@ -14614,7 +15381,9 @@ func ConvertFix64(memoryGauge common.MemoryGauge, value Value, locationRange Loc // allows us to call `v.Int64()` safely. if !v.IsInt64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return v.Int64() @@ -14740,7 +15509,9 @@ func NewUFix64ValueWithInteger(gauge common.MemoryGauge, constructor func() uint func NewUnmeteredUFix64ValueWithInteger(integer uint64, locationRange LocationRange) UFix64Value { if integer > sema.UFix64TypeMaxInt { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return NewUnmeteredUFix64Value(integer * sema.Fix64Factor) @@ -14800,7 +15571,7 @@ func (v UFix64Value) MeteredString(memoryGauge common.MemoryGauge, _ SeenReferen return v.String() } -func (v UFix64Value) ToInt(locationRange LocationRange) int { +func (v UFix64Value) ToInt(_ LocationRange) int { return int(v / sema.Fix64Factor) } @@ -14812,9 +15583,10 @@ func (v UFix64Value) Plus(interpreter *Interpreter, other NumberValue, locationR o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationPlus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationPlus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14829,9 +15601,10 @@ func (v UFix64Value) SaturatingPlus(interpreter *Interpreter, other NumberValue, o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingAddFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingAddFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14851,9 +15624,10 @@ func (v UFix64Value) Minus(interpreter *Interpreter, other NumberValue, location o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMinus, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMinus, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14862,7 +15636,9 @@ func (v UFix64Value) Minus(interpreter *Interpreter, other NumberValue, location // INT30-C if diff > v { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint64(diff) } @@ -14874,9 +15650,10 @@ func (v UFix64Value) SaturatingMinus(interpreter *Interpreter, other NumberValue o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingSubtractFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14897,9 +15674,10 @@ func (v UFix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMul, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMul, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14911,7 +15689,9 @@ func (v UFix64Value) Mul(interpreter *Interpreter, other NumberValue, locationRa result.Div(result, sema.Fix64FactorBig) if !result.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return result.Uint64() @@ -14924,9 +15704,10 @@ func (v UFix64Value) SaturatingMul(interpreter *Interpreter, other NumberValue, o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingMultiplyFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14951,9 +15732,10 @@ func (v UFix64Value) Div(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationDiv, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationDiv, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14975,9 +15757,10 @@ func (v UFix64Value) SaturatingDiv(interpreter *Interpreter, other NumberValue, r := recover() if _, ok := r.(InvalidOperandsError); ok { panic(InvalidOperandsError{ - FunctionName: sema.NumericTypeSaturatingDivideFunctionName, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + FunctionName: sema.NumericTypeSaturatingDivideFunctionName, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } }() @@ -14989,9 +15772,10 @@ func (v UFix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -14999,9 +15783,10 @@ func (v UFix64Value) Mod(interpreter *Interpreter, other NumberValue, locationRa quotient, ok := v.Div(interpreter, o, locationRange).(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationMod, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationMod, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -15023,9 +15808,10 @@ func (v UFix64Value) Less(interpreter *Interpreter, other ComparableValue, locat o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLess, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLess, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -15036,9 +15822,10 @@ func (v UFix64Value) LessEqual(interpreter *Interpreter, other ComparableValue, o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationLessEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationLessEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -15049,9 +15836,10 @@ func (v UFix64Value) Greater(interpreter *Interpreter, other ComparableValue, lo o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreater, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreater, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -15062,9 +15850,10 @@ func (v UFix64Value) GreaterEqual(interpreter *Interpreter, other ComparableValu o, ok := other.(UFix64Value) if !ok { panic(InvalidOperandsError{ - Operation: ast.OperationGreaterEqual, - LeftType: v.StaticType(interpreter), - RightType: other.StaticType(interpreter), + Operation: ast.OperationGreaterEqual, + LeftType: v.StaticType(interpreter), + RightType: other.StaticType(interpreter), + LocationRange: locationRange, }) } @@ -15095,7 +15884,9 @@ func ConvertUFix64(memoryGauge common.MemoryGauge, value Value, locationRange Lo case Fix64Value: if value < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return NewUFix64Value( memoryGauge, @@ -15109,7 +15900,9 @@ func ConvertUFix64(memoryGauge common.MemoryGauge, value Value, locationRange Lo v := value.ToBigInt(memoryGauge) if v.Sign() < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } // First, check if the value is at least in the uint64 range. @@ -15117,7 +15910,9 @@ func ConvertUFix64(memoryGauge common.MemoryGauge, value Value, locationRange Lo // allows us to call `v.UInt64()` safely. if !v.IsUint64() { - panic(OverflowError{LocationRange: locationRange}) + panic(OverflowError{ + LocationRange: locationRange, + }) } return v.Uint64() @@ -15130,7 +15925,9 @@ func ConvertUFix64(memoryGauge common.MemoryGauge, value Value, locationRange Lo converter := func() uint64 { v := value.ToInt(locationRange) if v < 0 { - panic(UnderflowError{LocationRange: locationRange}) + panic(UnderflowError{ + LocationRange: locationRange, + }) } return uint64(v) @@ -15493,7 +16290,7 @@ func (v *CompositeValue) Destroy(interpreter *Interpreter, locationRange Locatio var base *EphemeralReferenceValue var self MemberAccessibleValue = v if v.Kind == common.CompositeKindAttachment { - base, self = attachmentBaseAndSelfValues(interpreter, locationRange, v) + base, self = attachmentBaseAndSelfValues(interpreter, v) } invocation := NewInvocation( interpreter, @@ -15633,7 +16430,7 @@ func (v *CompositeValue) GetMember(interpreter *Interpreter, locationRange Locat var base *EphemeralReferenceValue var self MemberAccessibleValue = v if v.Kind == common.CompositeKindAttachment { - base, self = attachmentBaseAndSelfValues(interpreter, locationRange, v) + base, self = attachmentBaseAndSelfValues(interpreter, v) } return NewBoundFunctionValue(interpreter, function, &self, base) } @@ -16041,7 +16838,7 @@ func (v *CompositeValue) ConformsToStaticType( } if compositeType.Kind == common.CompositeKindAttachment { - base := v.getBaseValue(interpreter, locationRange).Value + base := v.getBaseValue().Value if base == nil || !base.ConformsToStaticType(interpreter, locationRange, results) { return false } @@ -16547,7 +17344,7 @@ func NewEnumCaseValue( return v } -func (v *CompositeValue) getBaseValue(interpreter *Interpreter, locationRange LocationRange) *EphemeralReferenceValue { +func (v *CompositeValue) getBaseValue() *EphemeralReferenceValue { return v.base } @@ -16592,10 +17389,9 @@ func (v *CompositeValue) GetAttachments(interpreter *Interpreter, locationRange func attachmentBaseAndSelfValues( interpreter *Interpreter, - locationRange LocationRange, v *CompositeValue, ) (base *EphemeralReferenceValue, self *EphemeralReferenceValue) { - base = v.getBaseValue(interpreter, locationRange) + base = v.getBaseValue() // in attachment functions, self is a reference value self = NewEphemeralReferenceValue(interpreter, false, v, interpreter.MustSemaTypeOfValue(v)) interpreter.trackReferencedResourceKindedValue(v.StorageID(), v) @@ -18959,8 +19755,8 @@ func (*EphemeralReferenceValue) IsImportable(_ *Interpreter) bool { } func (v *EphemeralReferenceValue) ReferencedValue( - interpreter *Interpreter, - locationRange LocationRange, + _ *Interpreter, + _ LocationRange, _ bool, ) *Value { return &v.Value diff --git a/runtime/literal.go b/runtime/literal.go index 521db21801..6b7d42ef37 100644 --- a/runtime/literal.go +++ b/runtime/literal.go @@ -97,7 +97,8 @@ func ParseLiteralArgumentList( parameterType := parameterTypes[i] value, err := LiteralValue(inter, argument.Expression, parameterType) if err != nil { - return nil, parser.NewUnpositionedSyntaxError( + return nil, parser.NewSyntaxError( + argument.Expression.StartPosition(), "invalid argument at index %d: %v", i, err, ) } diff --git a/runtime/parser/errors.go b/runtime/parser/errors.go index e870aacbd4..5e2381e8d2 100644 --- a/runtime/parser/errors.go +++ b/runtime/parser/errors.go @@ -74,6 +74,7 @@ func NewSyntaxError(pos ast.Position, message string, params ...any) *SyntaxErro func NewUnpositionedSyntaxError(message string, params ...any) *SyntaxError { return &SyntaxError{ + Pos: ast.Position{Line: 1}, Message: fmt.Sprintf(message, params...), } } From 937ff73e5a88a53df49874644ede7263e7e0ddfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 2 Aug 2023 17:08:44 -0700 Subject: [PATCH 11/17] ensure errors with location, position, and suggested fixes, can produce them --- runtime/tests/utils/utils.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/runtime/tests/utils/utils.go b/runtime/tests/utils/utils.go index c630385a63..8835a83c6b 100644 --- a/runtime/tests/utils/utils.go +++ b/runtime/tests/utils/utils.go @@ -28,8 +28,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/onflow/cadence/runtime/ast" "github.com/onflow/cadence/runtime/errors" "github.com/onflow/cadence/runtime/interpreter" + "github.com/onflow/cadence/runtime/sema" "github.com/onflow/cadence/runtime/common" ) @@ -207,6 +209,16 @@ func RequireError(t *testing.T, err error) { _ = err.Error() + if hasImportLocation, ok := err.(common.HasLocation); ok { + location := hasImportLocation.ImportLocation() + assert.NotNil(t, location) + } + + if hasPosition, ok := err.(ast.HasPosition); ok { + _ = hasPosition.StartPosition() + _ = hasPosition.EndPosition(nil) + } + if hasErrorNotes, ok := err.(errors.ErrorNotes); ok { for _, note := range hasErrorNotes.ErrorNotes() { _ = note.Message() @@ -216,4 +228,8 @@ func RequireError(t *testing.T, err error) { if hasSecondaryError, ok := err.(errors.SecondaryError); ok { _ = hasSecondaryError.SecondaryError() } + + if hasSuggestedFixes, ok := err.(sema.HasSuggestedFixes); ok { + _ = hasSuggestedFixes.SuggestFixes("") + } } From d278372235ca974ecff6bb2c7cf2b50fcadf09f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 2 Aug 2023 17:08:57 -0700 Subject: [PATCH 12/17] fix error types --- runtime/parser/expression.go | 6 +++--- runtime/parser/type.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runtime/parser/expression.go b/runtime/parser/expression.go index a6378b77bc..81620434a0 100644 --- a/runtime/parser/expression.go +++ b/runtime/parser/expression.go @@ -198,7 +198,7 @@ func defineExpr(def any) { func setExprNullDenotation(tokenType lexer.TokenType, nullDenotation exprNullDenotationFunc) { current := exprNullDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "expression null denotation for token %s already exists", tokenType, )) @@ -225,7 +225,7 @@ func setExprIdentifierLeftBindingPower(keyword string, power int) { func setExprLeftDenotation(tokenType lexer.TokenType, leftDenotation exprLeftDenotationFunc) { current := exprLeftDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "expression left denotation for token %s already exists", tokenType, )) @@ -237,7 +237,7 @@ func setExprLeftDenotation(tokenType lexer.TokenType, leftDenotation exprLeftDen func setExprMetaLeftDenotation(tokenType lexer.TokenType, metaLeftDenotation exprMetaLeftDenotationFunc) { current := exprMetaLeftDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "expression meta left denotation for token %s already exists", tokenType, )) diff --git a/runtime/parser/type.go b/runtime/parser/type.go index 1c862419a8..80b764b98f 100644 --- a/runtime/parser/type.go +++ b/runtime/parser/type.go @@ -53,7 +53,7 @@ var typeMetaLeftDenotations [lexer.TokenMax]typeMetaLeftDenotationFunc func setTypeNullDenotation(tokenType lexer.TokenType, nullDenotation typeNullDenotationFunc) { current := typeNullDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "type null denotation for token %s already exists", tokenType, )) @@ -72,7 +72,7 @@ func setTypeLeftBindingPower(tokenType lexer.TokenType, power int) { func setTypeLeftDenotation(tokenType lexer.TokenType, leftDenotation typeLeftDenotationFunc) { current := typeLeftDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "type left denotation for token %s already exists", tokenType, )) @@ -83,7 +83,7 @@ func setTypeLeftDenotation(tokenType lexer.TokenType, leftDenotation typeLeftDen func setTypeMetaLeftDenotation(tokenType lexer.TokenType, metaLeftDenotation typeMetaLeftDenotationFunc) { current := typeMetaLeftDenotations[tokenType] if current != nil { - panic(NewUnpositionedSyntaxError( + panic(errors.NewUnexpectedError( "type meta left denotation for token %s already exists", tokenType, )) From 440fb31386a1a67f5b6e21044f2a2a51013ef815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 3 Aug 2023 10:04:42 -0700 Subject: [PATCH 13/17] fix run for push --- .github/workflows/compatibility-check.yml | 2 +- .github/workflows/downstream.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compatibility-check.yml b/.github/workflows/compatibility-check.yml index 98456f56c3..9c67e53b09 100644 --- a/.github/workflows/compatibility-check.yml +++ b/.github/workflows/compatibility-check.yml @@ -53,7 +53,7 @@ jobs: echo "branch=`(echo "${{ github.event.pull_request.head.sha }}")`" >> $GITHUB_OUTPUT echo "base=`(echo "${{ github.base_ref }}")`" >> $GITHUB_OUTPUT else - echo "repo=`(echo "${{ inputs.repo || 'onflow/cadence' }}")`" >> $GITHUB_OUTPUT + echo "repo=`(echo "${{ inputs.repo || github.repository }}")`" >> $GITHUB_OUTPUT echo "branch=`(echo "${{ inputs.branch }}")`" >> $GITHUB_OUTPUT echo "base=`(echo "${{ inputs.base }}")`" >> $GITHUB_OUTPUT fi diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index aafb3c40a8..3f7862a6e0 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -39,7 +39,7 @@ jobs: run: sh crypto_setup.sh - name: Update Cadence - run: go mod edit -replace github.com/onflow/cadence=github.com/${{ github.event.pull_request.head.repo.full_name }}@${{ github.event.pull_request.head.sha }} + run: go mod edit -replace github.com/onflow/cadence=github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }}@${{ github.event.pull_request.head.sha || github.sha }} - name: Tidy up run: go mod tidy @@ -63,7 +63,7 @@ jobs: cache: true - name: Update Cadence - run: go mod edit -replace github.com/onflow/cadence=github.com/${{ github.event.pull_request.head.repo.full_name }}@${{ github.event.pull_request.head.sha }} + run: go mod edit -replace github.com/onflow/cadence=github.com/${{ github.event.pull_request.head.repo.full_name || github.repository }}@${{ github.event.pull_request.head.sha || github.sha }} - name: Tidy up run: go mod tidy From 8d83423f405176cc32f5dd50e3555571b5c109f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 3 Aug 2023 10:16:13 -0700 Subject: [PATCH 14/17] update to Go 1.20 --- .github/workflows/benchmark.yml | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/compatibility-check-template.yml | 2 +- .github/workflows/compatibility-check.yml | 2 +- .github/workflows/downstream.yml | 2 +- .github/workflows/release.yml | 2 +- go.mod | 2 +- tools/batch-script/go.mod | 2 +- tools/compatibility-check/go.mod | 2 +- tools/constructorcheck/go.mod | 2 +- tools/golangci-lint/go.mod | 4 ++-- tools/maprange/go.mod | 2 +- tools/unkeyed/go.mod | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 2700635531..a6be162cda 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -13,7 +13,7 @@ on: - 'v**' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9601b694a2..5a5e483d72 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ on: - 'v**' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index eab3c6b3f8..f7be868fdf 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,7 +13,7 @@ on: - 'v**' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/.github/workflows/compatibility-check-template.yml b/.github/workflows/compatibility-check-template.yml index 85879a62d3..fb849eafda 100644 --- a/.github/workflows/compatibility-check-template.yml +++ b/.github/workflows/compatibility-check-template.yml @@ -21,7 +21,7 @@ on: type: string env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ inputs.base-branch || github.run_id }}-${{ inputs.chain }} diff --git a/.github/workflows/compatibility-check.yml b/.github/workflows/compatibility-check.yml index 9c67e53b09..7c79e5ce10 100644 --- a/.github/workflows/compatibility-check.yml +++ b/.github/workflows/compatibility-check.yml @@ -23,7 +23,7 @@ on: - 'v**' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ inputs.base || github.run_id }} diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index 3f7862a6e0..bcdb98447a 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -13,7 +13,7 @@ on: - 'v**' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b51740600f..d79b11148c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ on: default: 'master' env: - GO_VERSION: '1.19.2' + GO_VERSION: '1.20' concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} diff --git a/go.mod b/go.mod index dcfe9cae70..6dfc1fb807 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence -go 1.18 +go 1.20 require ( github.com/bits-and-blooms/bitset v1.5.0 diff --git a/tools/batch-script/go.mod b/tools/batch-script/go.mod index 50521aad3a..39fb396bfa 100644 --- a/tools/batch-script/go.mod +++ b/tools/batch-script/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence/tools/batch-script -go 1.18 +go 1.20 require ( github.com/onflow/cadence v0.21.2 diff --git a/tools/compatibility-check/go.mod b/tools/compatibility-check/go.mod index 9cb961cde1..baed296863 100644 --- a/tools/compatibility-check/go.mod +++ b/tools/compatibility-check/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence/tools/compatibility_check -go 1.19 +go 1.20 require ( github.com/onflow/cadence v0.31.2-0.20230207221811-9eb6e7fe4121 diff --git a/tools/constructorcheck/go.mod b/tools/constructorcheck/go.mod index 1a9332f039..92a60226b2 100644 --- a/tools/constructorcheck/go.mod +++ b/tools/constructorcheck/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence/tools/constructorcheck -go 1.19 +go 1.20 require golang.org/x/tools v0.6.0 diff --git a/tools/golangci-lint/go.mod b/tools/golangci-lint/go.mod index 07fa12d3f7..cd92d2b227 100644 --- a/tools/golangci-lint/go.mod +++ b/tools/golangci-lint/go.mod @@ -1,6 +1,6 @@ -module github.com/filecoin-project/tools/golangci-lint +module github.com/onflow/cadence/tools/golangci-lint -go 1.19 +go 1.20 require github.com/golangci/golangci-lint v1.51.2 diff --git a/tools/maprange/go.mod b/tools/maprange/go.mod index f606575814..bc581c315e 100644 --- a/tools/maprange/go.mod +++ b/tools/maprange/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence/tools/maprange -go 1.19 +go 1.20 require golang.org/x/tools v0.6.0 diff --git a/tools/unkeyed/go.mod b/tools/unkeyed/go.mod index b002306faf..bb7edb9629 100644 --- a/tools/unkeyed/go.mod +++ b/tools/unkeyed/go.mod @@ -1,6 +1,6 @@ module github.com/onflow/cadence/tools/unkeyed -go 1.19 +go 1.20 require ( golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9 From f8d763e14de24a8a49a41d041e99f3c276194e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 3 Aug 2023 13:49:13 -0700 Subject: [PATCH 15/17] improve random value generation, use local random generator --- .../tests/interpreter/memory_metering_test.go | 6 +- runtime/tests/interpreter/values_test.go | 558 ++++++++---------- 2 files changed, 266 insertions(+), 298 deletions(-) diff --git a/runtime/tests/interpreter/memory_metering_test.go b/runtime/tests/interpreter/memory_metering_test.go index ddd0e577d3..22a8c38335 100644 --- a/runtime/tests/interpreter/memory_metering_test.go +++ b/runtime/tests/interpreter/memory_metering_test.go @@ -705,7 +705,8 @@ func TestInterpretSimpleCompositeMetering(t *testing.T) { meter := newTestMemoryGauge() inter := parseCheckAndInterpretWithMemoryMetering(t, script, meter) - _, err := inter.Invoke("main", newTestAuthAccountValue(meter, randomAddressValue())) + addressValue := newRandomValueGenerator().randomAddressValue() + _, err := inter.Invoke("main", newTestAuthAccountValue(meter, addressValue)) require.NoError(t, err) assert.Equal(t, uint64(1), meter.getMemory(common.MemoryKindSimpleCompositeValueBase)) @@ -724,7 +725,8 @@ func TestInterpretSimpleCompositeMetering(t *testing.T) { meter := newTestMemoryGauge() inter := parseCheckAndInterpretWithMemoryMetering(t, script, meter) - _, err := inter.Invoke("main", newTestPublicAccountValue(meter, randomAddressValue())) + addressValue := newRandomValueGenerator().randomAddressValue() + _, err := inter.Invoke("main", newTestPublicAccountValue(meter, addressValue)) require.NoError(t, err) assert.Equal(t, uint64(1), meter.getMemory(common.MemoryKindSimpleCompositeValueBase)) diff --git a/runtime/tests/interpreter/values_test.go b/runtime/tests/interpreter/values_test.go index e5ebe3336b..68233b183d 100644 --- a/runtime/tests/interpreter/values_test.go +++ b/runtime/tests/interpreter/values_test.go @@ -55,9 +55,8 @@ func TestRandomMapOperations(t *testing.T) { t.Parallel() - seed := time.Now().UnixNano() - fmt.Printf("Seed used for map opearations test: %d \n", seed) - rand.Seed(seed) + r := newRandomValueGenerator() + t.Logf("seed: %d", r.seed) storage := newUnmeteredInMemoryStorage() inter, err := interpreter.NewInterpreter( @@ -79,7 +78,7 @@ func TestRandomMapOperations(t *testing.T) { ) require.NoError(t, err) - numberOfValues := randomInt(containerMaxSize) + numberOfValues := r.randomInt(containerMaxSize) var testMap, copyOfTestMap *interpreter.DictionaryValue var storageSize, slabCounts int @@ -90,8 +89,8 @@ func TestRandomMapOperations(t *testing.T) { t.Run("construction", func(t *testing.T) { keyValues := make([]interpreter.Value, numberOfValues*2) for i := 0; i < numberOfValues; i++ { - key := randomHashableValue(inter) - value := randomStorableValue(inter, 0) + key := r.randomHashableValue(inter) + value := r.randomStorableValue(inter, 0) entries.put(inter, key, value) @@ -212,8 +211,8 @@ func TestRandomMapOperations(t *testing.T) { // Insert for i := 0; i < numberOfValues; i++ { - key := randomHashableValue(inter) - value := randomStorableValue(inter, 0) + key := r.randomHashableValue(inter) + value := r.randomStorableValue(inter, 0) newEntries.put(inter, key, value) @@ -240,8 +239,8 @@ func TestRandomMapOperations(t *testing.T) { keyValues := make([][2]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { - key := randomHashableValue(inter) - value := randomStorableValue(inter, 0) + key := r.randomHashableValue(inter) + value := r.randomStorableValue(inter, 0) newEntries.put(inter, key, value) @@ -317,7 +316,7 @@ func TestRandomMapOperations(t *testing.T) { keyValues := make([][2]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { // Create a random enum as key - key := generateRandomHashableValue(inter, Enum) + key := r.generateRandomHashableValue(inter, randomValueKindEnum) value := interpreter.Void newEntries.put(inter, key, value) @@ -361,7 +360,7 @@ func TestRandomMapOperations(t *testing.T) { // Generate unique key var key interpreter.Value for { - key = randomHashableValue(inter) + key = r.randomHashableValue(inter) var foundConflict bool for j := 0; j < i; j++ { @@ -377,7 +376,7 @@ func TestRandomMapOperations(t *testing.T) { } keyValues[i][0] = key - keyValues[i][1] = randomStorableValue(inter, 0) + keyValues[i][1] = r.randomStorableValue(inter, 0) } dictionary := interpreter.NewDictionaryValueWithAddress( @@ -407,7 +406,7 @@ func TestRandomMapOperations(t *testing.T) { return false } - return randomInt(1) == 1 + return r.randomInt(1) == 1 } for insertCount < numberOfValues || dictionary.Count() > 0 { @@ -461,8 +460,8 @@ func TestRandomMapOperations(t *testing.T) { keyValues := make([]interpreter.Value, numberOfValues*2) for i := 0; i < numberOfValues; i++ { - key := randomHashableValue(inter) - value := randomStorableValue(inter, 0) + key := r.randomHashableValue(inter) + value := r.randomStorableValue(inter, 0) entries.put(inter, key, value) @@ -520,9 +519,8 @@ func TestRandomArrayOperations(t *testing.T) { t.Skip("smoke tests are disabled") } - seed := time.Now().UnixNano() - fmt.Printf("Seed used for array opearations test: %d \n", seed) - rand.Seed(seed) + r := newRandomValueGenerator() + t.Logf("seed: %d", r.seed) storage := newUnmeteredInMemoryStorage() inter, err := interpreter.NewInterpreter( @@ -542,7 +540,7 @@ func TestRandomArrayOperations(t *testing.T) { ) require.NoError(t, err) - numberOfValues := randomInt(containerMaxSize) + numberOfValues := r.randomInt(containerMaxSize) var testArray, copyOfTestArray *interpreter.ArrayValue var storageSize, slabCounts int @@ -553,7 +551,7 @@ func TestRandomArrayOperations(t *testing.T) { t.Run("construction", func(t *testing.T) { values := make([]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { - value := randomStorableValue(inter, 0) + value := r.randomStorableValue(inter, 0) elements[i] = value values[i] = value.Clone(inter) } @@ -656,7 +654,7 @@ func TestRandomArrayOperations(t *testing.T) { require.Equal(t, 0, testArray.Count()) for i := 0; i < numberOfValues; i++ { - element := randomStorableValue(inter, 0) + element := r.randomStorableValue(inter, 0) newElements[i] = element testArray.Insert( @@ -691,7 +689,7 @@ func TestRandomArrayOperations(t *testing.T) { require.Equal(t, 0, testArray.Count()) for i := 0; i < numberOfValues; i++ { - element := randomStorableValue(inter, 0) + element := r.randomStorableValue(inter, 0) newElements[i] = element testArray.Append( @@ -714,7 +712,7 @@ func TestRandomArrayOperations(t *testing.T) { newElements := make([]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { - newElements[i] = randomStorableValue(inter, 0) + newElements[i] = r.randomStorableValue(inter, 0) } testArray = interpreter.NewArrayValue( @@ -765,7 +763,7 @@ func TestRandomArrayOperations(t *testing.T) { elements := make([]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { - elements[i] = randomStorableValue(inter, 0) + elements[i] = r.randomStorableValue(inter, 0) } testArray = interpreter.NewArrayValue( @@ -794,7 +792,7 @@ func TestRandomArrayOperations(t *testing.T) { return false } - return randomInt(1) == 1 + return r.randomInt(1) == 1 } for insertCount < numberOfValues || testArray.Count() > 0 { @@ -834,7 +832,7 @@ func TestRandomArrayOperations(t *testing.T) { elements := make([]interpreter.Value, numberOfValues) for i := 0; i < numberOfValues; i++ { - value := randomStorableValue(inter, 0) + value := r.randomStorableValue(inter, 0) elements[i] = value values[i] = value.Clone(inter) } @@ -886,9 +884,8 @@ func TestRandomCompositeValueOperations(t *testing.T) { t.Skip("smoke tests are disabled") } - seed := time.Now().UnixNano() - fmt.Printf("Seed used for compsoite opearations test: %d \n", seed) - rand.Seed(seed) + r := newRandomValueGenerator() + t.Logf("seed: %d", r.seed) storage := newUnmeteredInMemoryStorage() inter, err := interpreter.NewInterpreter( @@ -912,11 +909,11 @@ func TestRandomCompositeValueOperations(t *testing.T) { var storageSize, slabCounts int var orgFields map[string]interpreter.Value - fieldsCount := randomInt(compositeMaxFields) + fieldsCount := r.randomInt(compositeMaxFields) orgOwner := common.Address{'A'} t.Run("construction", func(t *testing.T) { - testComposite, orgFields = newCompositeValue(orgOwner, fieldsCount, inter) + testComposite, orgFields = r.randomCompositeValue(orgOwner, fieldsCount, inter, 0) storageSize, slabCounts = getSlabStorageSize(t, storage) @@ -1004,7 +1001,7 @@ func TestRandomCompositeValueOperations(t *testing.T) { }) t.Run("move", func(t *testing.T) { - composite, fields := newCompositeValue(orgOwner, fieldsCount, inter) + composite, fields := r.randomCompositeValue(orgOwner, fieldsCount, inter, 0) owner := composite.GetOwner() assert.Equal(t, orgOwner, owner) @@ -1034,15 +1031,16 @@ func TestRandomCompositeValueOperations(t *testing.T) { }) } -func newCompositeValue( +func (r randomValueGenerator) randomCompositeValue( orgOwner common.Address, fieldsCount int, inter *interpreter.Interpreter, + currentDepth int, ) (*interpreter.CompositeValue, map[string]interpreter.Value) { orgFields := make(map[string]interpreter.Value, fieldsCount) - identifier := randomUTF8String() + identifier := r.randomUTF8String() location := common.AddressLocation{ Address: orgOwner, @@ -1054,7 +1052,7 @@ func newCompositeValue( fieldNames := make(map[string]any, fieldsCount) for i := 0; i < fieldsCount; { - fieldName := randomUTF8String() + fieldName := r.randomUTF8String() // avoid duplicate field names if _, ok := fieldNames[fieldName]; ok { @@ -1064,7 +1062,7 @@ func newCompositeValue( field := interpreter.NewUnmeteredCompositeField( fieldName, - randomStorableValue(inter, 0), + r.randomStorableValue(inter, currentDepth+1), ) fields[i] = field @@ -1128,158 +1126,183 @@ func getSlabStorageSize(t *testing.T, storage interpreter.InMemoryStorage) (tota return } -func randomStorableValue(inter *interpreter.Interpreter, currentDepth int) interpreter.Value { +type randomValueGenerator struct { + seed int64 + rand *rand.Rand +} + +func newRandomValueGenerator() randomValueGenerator { + seed := time.Now().UnixNano() + + return randomValueGenerator{ + seed: seed, + rand: rand.New(rand.NewSource(seed)), + } +} +func (r randomValueGenerator) randomStorableValue(inter *interpreter.Interpreter, currentDepth int) interpreter.Value { n := 0 if currentDepth < containerMaxDepth { - n = randomInt(Composite) + n = r.randomInt(randomValueKindComposite) } else { - n = randomInt(IDCapability) + n = r.randomInt(randomValueKindIDCapability) } switch n { // Non-hashable - case Void: + case randomValueKindVoid: return interpreter.Void - case Nil: + case randomValueKindNil: return interpreter.Nil - case Dictionary_1, Dictionary_2: - return randomDictionaryValue(inter, currentDepth) - case Array_1, Array_2: - return randomArrayValue(inter, currentDepth) - case Composite: - return randomCompositeValue(inter, common.CompositeKindStructure, currentDepth) - case PathCapability: + case randomValueKindDictionaryVariant1, + randomValueKindDictionaryVariant2: + return r.randomDictionaryValue(inter, currentDepth) + case randomValueKindArrayVariant1, + randomValueKindArrayVariant2: + return r.randomArrayValue(inter, currentDepth) + case randomValueKindComposite: + fieldsCount := r.randomInt(compositeMaxFields) + v, _ := r.randomCompositeValue(common.ZeroAddress, fieldsCount, inter, currentDepth) + return v + case randomValueKindPathCapability: return interpreter.NewUnmeteredPathCapabilityValue( - randomAddressValue(), - randomPathValue(), + r.randomAddressValue(), + r.randomPathValue(), interpreter.ReferenceStaticType{ Authorized: false, BorrowedType: interpreter.PrimitiveStaticTypeAnyStruct, }, ) - case IDCapability: + case randomValueKindIDCapability: return interpreter.NewUnmeteredIDCapabilityValue( - interpreter.UInt64Value(randomInt(math.MaxInt-1)), - randomAddressValue(), + interpreter.UInt64Value(r.randomInt(math.MaxInt-1)), + r.randomAddressValue(), interpreter.ReferenceStaticType{ Authorized: false, BorrowedType: interpreter.PrimitiveStaticTypeAnyStruct, }, ) - case Some: + case randomValueKindSome: return interpreter.NewUnmeteredSomeValueNonCopying( - randomStorableValue(inter, currentDepth+1), + r.randomStorableValue(inter, currentDepth+1), ) // Hashable default: - return generateRandomHashableValue(inter, n) + return r.generateRandomHashableValue(inter, n) } } -func randomHashableValue(interpreter *interpreter.Interpreter) interpreter.Value { - return generateRandomHashableValue(interpreter, randomInt(Enum)) +func (r randomValueGenerator) randomHashableValue(interpreter *interpreter.Interpreter) interpreter.Value { + return r.generateRandomHashableValue(interpreter, r.randomInt(randomValueKindEnum)) } -func generateRandomHashableValue(inter *interpreter.Interpreter, n int) interpreter.Value { +func (r randomValueGenerator) generateRandomHashableValue(inter *interpreter.Interpreter, n int) interpreter.Value { switch n { - // Int - case Int: - return interpreter.NewUnmeteredIntValueFromInt64(int64(sign()) * rand.Int63()) - case Int8: - return interpreter.NewUnmeteredInt8Value(int8(randomInt(math.MaxUint8))) - case Int16: - return interpreter.NewUnmeteredInt16Value(int16(randomInt(math.MaxUint16))) - case Int32: - return interpreter.NewUnmeteredInt32Value(int32(sign()) * rand.Int31()) - case Int64: - return interpreter.NewUnmeteredInt64Value(int64(sign()) * rand.Int63()) - case Int128: - return interpreter.NewUnmeteredInt128ValueFromInt64(int64(sign()) * rand.Int63()) - case Int256: - return interpreter.NewUnmeteredInt256ValueFromInt64(int64(sign()) * rand.Int63()) - - // UInt - case UInt: - return interpreter.NewUnmeteredUIntValueFromUint64(rand.Uint64()) - case UInt8: - return interpreter.NewUnmeteredUInt8Value(uint8(randomInt(math.MaxUint8))) - case UInt16: - return interpreter.NewUnmeteredUInt16Value(uint16(randomInt(math.MaxUint16))) - case UInt32: - return interpreter.NewUnmeteredUInt32Value(rand.Uint32()) - case UInt64_1, UInt64_2, UInt64_3, UInt64_4: // should be more common - return interpreter.NewUnmeteredUInt64Value(rand.Uint64()) - case UInt128: - return interpreter.NewUnmeteredUInt128ValueFromUint64(rand.Uint64()) - case UInt256: - return interpreter.NewUnmeteredUInt256ValueFromUint64(rand.Uint64()) - - // Word - case Word8: - return interpreter.NewUnmeteredWord8Value(uint8(randomInt(math.MaxUint8))) - case Word16: - return interpreter.NewUnmeteredWord16Value(uint16(randomInt(math.MaxUint16))) - case Word32: - return interpreter.NewUnmeteredWord32Value(rand.Uint32()) - case Word64: - return interpreter.NewUnmeteredWord64Value(rand.Uint64()) - case Word128: - return interpreter.NewUnmeteredWord128ValueFromUint64(rand.Uint64()) - case Word256: - return interpreter.NewUnmeteredWord256ValueFromUint64(rand.Uint64()) - - // Fixed point - case Fix64: - return interpreter.NewUnmeteredFix64ValueWithInteger(int64(sign())*rand.Int63n(sema.Fix64TypeMaxInt), interpreter.EmptyLocationRange) - case UFix64: + // Int* + case randomValueKindInt: + return interpreter.NewUnmeteredIntValueFromInt64(int64(r.randomSign()) * r.rand.Int63()) + case randomValueKindInt8: + return interpreter.NewUnmeteredInt8Value(int8(r.randomInt(math.MaxUint8))) + case randomValueKindInt16: + return interpreter.NewUnmeteredInt16Value(int16(r.randomInt(math.MaxUint16))) + case randomValueKindInt32: + return interpreter.NewUnmeteredInt32Value(int32(r.randomSign()) * r.rand.Int31()) + case randomValueKindInt64: + return interpreter.NewUnmeteredInt64Value(int64(r.randomSign()) * r.rand.Int63()) + case randomValueKindInt128: + return interpreter.NewUnmeteredInt128ValueFromInt64(int64(r.randomSign()) * r.rand.Int63()) + case randomValueKindInt256: + return interpreter.NewUnmeteredInt256ValueFromInt64(int64(r.randomSign()) * r.rand.Int63()) + + // UInt* + case randomValueKindUInt: + return interpreter.NewUnmeteredUIntValueFromUint64(r.rand.Uint64()) + case randomValueKindUInt8: + return interpreter.NewUnmeteredUInt8Value(uint8(r.randomInt(math.MaxUint8))) + case randomValueKindUInt16: + return interpreter.NewUnmeteredUInt16Value(uint16(r.randomInt(math.MaxUint16))) + case randomValueKindUInt32: + return interpreter.NewUnmeteredUInt32Value(r.rand.Uint32()) + case randomValueKindUInt64Variant1, + randomValueKindUInt64Variant2, + randomValueKindUInt64Variant3, + randomValueKindUInt64Variant4: // should be more common + return interpreter.NewUnmeteredUInt64Value(r.rand.Uint64()) + case randomValueKindUInt128: + return interpreter.NewUnmeteredUInt128ValueFromUint64(r.rand.Uint64()) + case randomValueKindUInt256: + return interpreter.NewUnmeteredUInt256ValueFromUint64(r.rand.Uint64()) + + // Word* + case randomValueKindWord8: + return interpreter.NewUnmeteredWord8Value(uint8(r.randomInt(math.MaxUint8))) + case randomValueKindWord16: + return interpreter.NewUnmeteredWord16Value(uint16(r.randomInt(math.MaxUint16))) + case randomValueKindWord32: + return interpreter.NewUnmeteredWord32Value(r.rand.Uint32()) + case randomValueKindWord64: + return interpreter.NewUnmeteredWord64Value(r.rand.Uint64()) + case randomValueKindWord128: + return interpreter.NewUnmeteredWord128ValueFromUint64(r.rand.Uint64()) + case randomValueKindWord256: + return interpreter.NewUnmeteredWord256ValueFromUint64(r.rand.Uint64()) + + // (U)Fix* + case randomValueKindFix64: + return interpreter.NewUnmeteredFix64ValueWithInteger( + int64(r.randomSign())*r.rand.Int63n(sema.Fix64TypeMaxInt), + interpreter.EmptyLocationRange, + ) + case randomValueKindUFix64: return interpreter.NewUnmeteredUFix64ValueWithInteger( - uint64(rand.Int63n( + uint64(r.rand.Int63n( int64(sema.UFix64TypeMaxInt), )), interpreter.EmptyLocationRange, ) // String - case String_1, String_2, String_3, String_4: // small string - should be more common - size := randomInt(255) - return interpreter.NewUnmeteredStringValue(randomUTF8StringOfSize(size)) - case String_5: // large string - size := randomInt(4048) + 255 - return interpreter.NewUnmeteredStringValue(randomUTF8StringOfSize(size)) - - case Bool_True: + case randomValueKindStringVariant1, + randomValueKindStringVariant2, + randomValueKindStringVariant3, + randomValueKindStringVariant4: // small string - should be more common + size := r.randomInt(255) + return interpreter.NewUnmeteredStringValue(r.randomUTF8StringOfSize(size)) + case randomValueKindStringVariant5: // large string + size := r.randomInt(4048) + 255 + return interpreter.NewUnmeteredStringValue(r.randomUTF8StringOfSize(size)) + + case randomValueKindBoolVariantTrue: return interpreter.TrueValue - case Bool_False: + case randomValueKindBoolVariantFalse: return interpreter.FalseValue - case Address: - return randomAddressValue() + case randomValueKindAddress: + return r.randomAddressValue() - case Path: - return randomPathValue() + case randomValueKindPath: + return r.randomPathValue() - case Enum: + case randomValueKindEnum: // Get a random integer subtype to be used as the raw-type of enum - typ := randomInt(Word64) + typ := r.randomInt(randomValueKindWord64) - rawValue := generateRandomHashableValue(inter, typ).(interpreter.NumberValue) + rawValue := r.generateRandomHashableValue(inter, typ).(interpreter.NumberValue) - identifier := randomUTF8String() + identifier := r.randomUTF8String() - address := make([]byte, 8) - rand.Read(address) + address := r.randomAddressValue() location := common.AddressLocation{ - Address: common.MustBytesToAddress(address), + Address: common.Address(address), Name: identifier, } enumType := &sema.CompositeType{ Identifier: identifier, - EnumRawType: intSubtype(typ), + EnumRawType: r.intSubtype(typ), Kind: common.CompositeKindEnum, Location: location, } @@ -1311,27 +1334,27 @@ func generateRandomHashableValue(inter *interpreter.Interpreter, n int) interpre return enum default: - panic(fmt.Sprintf("unsupported: %d", n)) + panic(fmt.Sprintf("unsupported: %d", n)) } } -func sign() int { - if randomInt(1) == 1 { +func (r randomValueGenerator) randomSign() int { + if r.randomInt(1) == 1 { return 1 } return -1 } -func randomAddressValue() interpreter.AddressValue { +func (r randomValueGenerator) randomAddressValue() interpreter.AddressValue { data := make([]byte, 8) - rand.Read(data) + r.rand.Read(data) return interpreter.NewUnmeteredAddressValueFromBytes(data) } -func randomPathValue() interpreter.PathValue { - randomDomain := rand.Intn(len(common.AllPathDomains)) - identifier := randomUTF8String() +func (r randomValueGenerator) randomPathValue() interpreter.PathValue { + randomDomain := r.rand.Intn(len(common.AllPathDomains)) + identifier := r.randomUTF8String() return interpreter.PathValue{ Domain: common.AllPathDomains[randomDomain], @@ -1339,17 +1362,17 @@ func randomPathValue() interpreter.PathValue { } } -func randomDictionaryValue( +func (r randomValueGenerator) randomDictionaryValue( inter *interpreter.Interpreter, currentDepth int, ) interpreter.Value { - entryCount := randomInt(innerContainerMaxSize) + entryCount := r.randomInt(innerContainerMaxSize) keyValues := make([]interpreter.Value, entryCount*2) for i := 0; i < entryCount; i++ { - key := randomHashableValue(inter) - value := randomStorableValue(inter, currentDepth+1) + key := r.randomHashableValue(inter) + value := r.randomStorableValue(inter, currentDepth+1) keyValues[i*2] = key keyValues[i*2+1] = value } @@ -1366,16 +1389,16 @@ func randomDictionaryValue( ) } -func randomInt(upperBound int) int { - return rand.Intn(upperBound + 1) +func (r randomValueGenerator) randomInt(upperBound int) int { + return r.rand.Intn(upperBound + 1) } -func randomArrayValue(inter *interpreter.Interpreter, currentDepth int) interpreter.Value { - elementsCount := randomInt(innerContainerMaxSize) +func (r randomValueGenerator) randomArrayValue(inter *interpreter.Interpreter, currentDepth int) interpreter.Value { + elementsCount := r.randomInt(innerContainerMaxSize) elements := make([]interpreter.Value, elementsCount) for i := 0; i < elementsCount; i++ { - value := randomStorableValue(inter, currentDepth+1) + value := r.randomStorableValue(inter, currentDepth+1) elements[i] = value.Clone(inter) } @@ -1390,182 +1413,135 @@ func randomArrayValue(inter *interpreter.Interpreter, currentDepth int) interpre ) } -func randomCompositeValue( - inter *interpreter.Interpreter, - kind common.CompositeKind, - currentDepth int, -) interpreter.Value { - - identifier := randomUTF8String() - - address := make([]byte, 8) - rand.Read(address) - - location := common.AddressLocation{ - Address: common.MustBytesToAddress(address), - Name: identifier, - } - - fieldsCount := randomInt(compositeMaxFields) - fields := make([]interpreter.CompositeField, fieldsCount) - - for i := 0; i < fieldsCount; i++ { - fieldName := randomUTF8String() - - fields[i] = interpreter.NewUnmeteredCompositeField( - fieldName, - randomStorableValue(inter, currentDepth+1), - ) - } - - compositeType := &sema.CompositeType{ - Location: location, - Identifier: identifier, - Kind: kind, - } - - compositeType.Members = &sema.StringMemberOrderedMap{} - for _, field := range fields { - compositeType.Members.Set( - field.Name, - sema.NewUnmeteredPublicConstantFieldMember( - compositeType, - field.Name, - sema.AnyStructType, // TODO: handle resources - "", - ), - ) - } - - // Add the type to the elaboration, to short-circuit the type-lookup - inter.Program.Elaboration.SetCompositeType( - compositeType.ID(), - compositeType, - ) - - return interpreter.NewCompositeValue( - inter, - interpreter.EmptyLocationRange, - location, - identifier, - kind, - fields, - common.ZeroAddress, - ) -} - -func intSubtype(n int) sema.Type { +func (r randomValueGenerator) intSubtype(n int) sema.Type { switch n { // Int - case Int: + case randomValueKindInt: return sema.IntType - case Int8: + case randomValueKindInt8: return sema.Int8Type - case Int16: + case randomValueKindInt16: return sema.Int16Type - case Int32: + case randomValueKindInt32: return sema.Int32Type - case Int64: + case randomValueKindInt64: return sema.Int64Type - case Int128: + case randomValueKindInt128: return sema.Int128Type - case Int256: + case randomValueKindInt256: return sema.Int256Type // UInt - case UInt: + case randomValueKindUInt: return sema.UIntType - case UInt8: + case randomValueKindUInt8: return sema.UInt8Type - case UInt16: + case randomValueKindUInt16: return sema.UInt16Type - case UInt32: + case randomValueKindUInt32: return sema.UInt32Type - case UInt64_1, UInt64_2, UInt64_3, UInt64_4: + case randomValueKindUInt64Variant1, + randomValueKindUInt64Variant2, + randomValueKindUInt64Variant3, + randomValueKindUInt64Variant4: return sema.UInt64Type - case UInt128: + case randomValueKindUInt128: return sema.UInt128Type - case UInt256: + case randomValueKindUInt256: return sema.UInt256Type // Word - case Word8: + case randomValueKindWord8: return sema.Word8Type - case Word16: + case randomValueKindWord16: return sema.Word16Type - case Word32: + case randomValueKindWord32: return sema.Word32Type - case Word64: + case randomValueKindWord64: return sema.Word64Type - case Word128: + case randomValueKindWord128: return sema.Word128Type - case Word256: + case randomValueKindWord256: return sema.Word256Type default: - panic(fmt.Sprintf("unsupported: %d", n)) + panic(fmt.Sprintf("unsupported: %d", n)) } } const ( // Hashable values - Int = iota - Int8 - Int16 - Int32 - Int64 - Int128 - Int256 - - UInt - UInt8 - UInt16 - UInt32 - UInt64_1 - UInt64_2 - UInt64_3 - UInt64_4 - UInt128 - UInt256 - - Word8 - Word16 - Word32 - Word64 - Word128 - Word256 - - Fix64 - UFix64 - - String_1 - String_2 - String_3 - String_4 - String_5 - - Bool_True - Bool_False - Path - Address - Enum + // Int* + randomValueKindInt = iota + randomValueKindInt8 + randomValueKindInt16 + randomValueKindInt32 + randomValueKindInt64 + randomValueKindInt128 + randomValueKindInt256 + + // UInt* + randomValueKindUInt + randomValueKindUInt8 + randomValueKindUInt16 + randomValueKindUInt32 + randomValueKindUInt64Variant1 + randomValueKindUInt64Variant2 + randomValueKindUInt64Variant3 + randomValueKindUInt64Variant4 + randomValueKindUInt128 + randomValueKindUInt256 + + // Word* + randomValueKindWord8 + randomValueKindWord16 + randomValueKindWord32 + randomValueKindWord64 + randomValueKindWord128 + randomValueKindWord256 + + // (U)Fix* + randomValueKindFix64 + randomValueKindUFix64 - // Non-hashable values + // String + randomValueKindStringVariant1 + randomValueKindStringVariant2 + randomValueKindStringVariant3 + randomValueKindStringVariant4 + randomValueKindStringVariant5 + + randomValueKindBoolVariantTrue + randomValueKindBoolVariantFalse + randomValueKindPath + randomValueKindAddress + randomValueKindEnum - Void - Nil // `Never?` - PathCapability - IDCapability + // Non-hashable values + randomValueKindVoid + randomValueKindNil // `Never?` + randomValueKindPathCapability + randomValueKindIDCapability // Containers - Some - Array_1 - Array_2 - Dictionary_1 - Dictionary_2 - Composite + randomValueKindSome + randomValueKindArrayVariant1 + randomValueKindArrayVariant2 + randomValueKindDictionaryVariant1 + randomValueKindDictionaryVariant2 + randomValueKindComposite ) +func (r randomValueGenerator) randomUTF8String() string { + return r.randomUTF8StringOfSize(8) +} + +func (r randomValueGenerator) randomUTF8StringOfSize(size int) string { + identifier := make([]byte, size) + r.rand.Read(identifier) + return strings.ToValidUTF8(string(identifier), "$") +} + type valueMap struct { values map[any]interpreter.Value keys map[any]interpreter.Value @@ -1636,13 +1612,3 @@ func (m *valueMap) internalKey(inter *interpreter.Interpreter, key interpreter.V func (m *valueMap) size() int { return len(m.keys) } - -func randomUTF8String() string { - return randomUTF8StringOfSize(8) -} - -func randomUTF8StringOfSize(size int) string { - identifier := make([]byte, size) - rand.Read(identifier) - return strings.ToValidUTF8(string(identifier), "$") -} From 9962b8590ad3c47d211acc409168e702ba1b5a8b Mon Sep 17 00:00:00 2001 From: turbolent Date: Thu, 3 Aug 2023 21:58:58 +0000 Subject: [PATCH 16/17] v0.40.0 --- npm-packages/cadence-parser/package.json | 2 +- version.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index be6755e3ab..eb05dc83e8 100644 --- a/npm-packages/cadence-parser/package.json +++ b/npm-packages/cadence-parser/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-parser", - "version": "0.39.14", + "version": "0.40.0", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/version.go b/version.go index 4eba6881ed..7f8e0767df 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package cadence -const Version = "v0.39.14" +const Version = "v0.40.0" From ca4d44b14346912aa3a85882311fbd34563df137 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Tue, 8 Aug 2023 13:22:11 -0700 Subject: [PATCH 17/17] Update storage iteration value check + tests --- runtime/interpreter/interpreter.go | 83 +++++----- runtime/storage_test.go | 239 +++++++++++++++++++++++++---- 2 files changed, 250 insertions(+), 72 deletions(-) diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 4f38227195..8bbe9d7f76 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -4040,16 +4040,9 @@ func (interpreter *Interpreter) newStorageIterationFunction( staticType := value.StaticType(inter) - // TODO: unfortunately, the iterator only returns an atree.Value, not a StorageMapKey - identifier := string(key.(StringAtreeValue)) - pathValue := NewPathValue(inter, domain, identifier) - runtimeType := NewTypeValue(inter, staticType) - // Perform a forced value de-referencing to see if the associated type is not broken. // If broken, skip this value from the iteration. valueError := inter.checkValue( - address, - pathValue, value, staticType, invocation.LocationRange, @@ -4059,6 +4052,11 @@ func (interpreter *Interpreter) newStorageIterationFunction( continue } + // TODO: unfortunately, the iterator only returns an atree.Value, not a StorageMapKey + identifier := string(key.(StringAtreeValue)) + pathValue := NewPathValue(inter, domain, identifier) + runtimeType := NewTypeValue(inter, staticType) + subInvocation := NewInvocation( inter, nil, @@ -4101,8 +4099,6 @@ func (interpreter *Interpreter) newStorageIterationFunction( } func (interpreter *Interpreter) checkValue( - address common.Address, - path PathValue, value Value, staticType StaticType, locationRange LocationRange, @@ -4125,38 +4121,43 @@ func (interpreter *Interpreter) checkValue( } }() - // TODO: - //// Here, the value at the path could be either: - //// 1) The actual stored value (storage path) - //// 2) A link to the value at the storage (private/public paths) - //// - //// Therefore, try to find the final path, and try loading the value. - // - //// However, borrow type is not statically known. - //// So take the borrow type from the value itself - // - //var borrowType StaticType - //if _, ok := value.(LinkValue); ok { - // // Link values always have a `CapabilityStaticType` static type. - // borrowType = staticType.(CapabilityStaticType).BorrowType - //} else { - // // Reference type with value's type (i.e. `staticType`) as both the borrow type and the referenced type. - // borrowType = NewReferenceStaticType(interpreter, false, staticType, staticType) - //} - // - //var semaType sema.Type - //semaType, valueError = interpreter.ConvertStaticToSemaType(borrowType) - //if valueError != nil { - // return valueError - //} - // - //// This is guaranteed to be a reference type, because `borrowType` is always a reference. - //referenceType, ok := semaType.(*sema.ReferenceType) - //if !ok { - // panic(errors.NewUnreachableError()) - //} - // - //_, valueError = interpreter.checkValueAtPath(address, path, referenceType, locationRange) + // Here, the value at the path could be either: + // 1) The actual stored value (storage path) + // 2) A capability to the value at the storage (private/public paths) + + if idCapability, ok := value.(*IDCapabilityValue); ok { + // If, the value is a capability, try to load the value at the capability target. + // However, borrow type is not statically known. + // So take the borrow type from the value itself + + // Capability values always have a `CapabilityStaticType` static type. + borrowType := staticType.(CapabilityStaticType).BorrowType + + var borrowSemaType sema.Type + borrowSemaType, valueError = interpreter.ConvertStaticToSemaType(borrowType) + if valueError != nil { + return valueError + } + + referenceType, ok := borrowSemaType.(*sema.ReferenceType) + if !ok { + panic(errors.NewUnreachableError()) + } + + _ = interpreter.SharedState.Config.IDCapabilityCheckHandler( + interpreter, + locationRange, + idCapability.Address, + idCapability.ID, + referenceType, + referenceType, + ) + + } else { + // For all other values, trying to load the type is sufficient. + // Here it is only interested in whether the type can be properly loaded. + _, valueError = interpreter.ConvertStaticToSemaType(staticType) + } return } diff --git a/runtime/storage_test.go b/runtime/storage_test.go index 65b0b2b590..e66bd0d845 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -3688,7 +3688,7 @@ func TestRuntimeStorageIteration(t *testing.T) { require.NoError(t, err) }) - t.Run("broken impl, linked with interface", func(t *testing.T) { + t.Run("broken impl, stored with interface", func(t *testing.T) { t.Parallel() @@ -3701,7 +3701,7 @@ func TestRuntimeStorageIteration(t *testing.T) { deployFoo := DeploymentTransaction("Foo", []byte(` access(all) contract Foo { - access(all) resource interface Collection {} + access(all) struct interface Collection {} } `)) @@ -3709,11 +3709,7 @@ func TestRuntimeStorageIteration(t *testing.T) { import Foo from 0x1 access(all) contract Bar { - access(all) resource CollectionImpl: Foo.Collection {} - - access(all) fun getCollection(): @Bar.CollectionImpl { - return <- create Bar.CollectionImpl() - } + access(all) struct CollectionImpl: Foo.Collection {} } `)) @@ -3735,7 +3731,7 @@ func TestRuntimeStorageIteration(t *testing.T) { import Foo from 0x1 access(all) contract Bar { - access(all) resource CollectionImpl: Foo.Collection { + access(all) struct CollectionImpl: Foo.Collection { access(all) var mismatch: Int init() { @@ -3754,7 +3750,7 @@ func TestRuntimeStorageIteration(t *testing.T) { } } - // Deploy ``Foo` contract + // Deploy `Foo` contract runtimeInterface := newRuntimeInterface() @@ -3795,13 +3791,15 @@ func TestRuntimeStorageIteration(t *testing.T) { transaction { prepare(signer: AuthAccount) { signer.save("Hello, World!", to: /storage/first) - signer.save(<- Bar.getCollection(), to: /storage/second) - signer.link<&String>(/private/a, target:/storage/first) - signer.link<&AnyResource{Foo.Collection}>(/private/b, target:/storage/second) + var structArray: [{Foo.Collection}] = [Bar.CollectionImpl()] + signer.save(structArray, to: /storage/second) + + let capA = signer.capabilities.storage.issue<&String>(/storage/first) + signer.capabilities.publish(capA, at: /public/a) - signer.link<&String>(/public/a, target:/storage/first) - signer.link<&AnyResource{Foo.Collection}>(/public/b, target:/storage/second) + let capB = signer.capabilities.storage.issue<&[{Foo.Collection}]>(/storage/second) + signer.capabilities.publish(capB, at: /public/b) } } `), @@ -3828,16 +3826,21 @@ func TestRuntimeStorageIteration(t *testing.T) { transaction { prepare(account: AuthAccount) { var total = 0 + var capTaken = false + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { - var cap = account.getCapability<&AnyResource{Foo.Collection}>(path) - cap.check() total = total + 1 + if var cap = account.capabilities.get<&[{Foo.Collection}]>(path) { + cap.check() + var refArray = cap.borrow()! + capTaken = true + } + return true }) - // Total values iterated should be 1. - // The broken value must be skipped. - assert(total == 1) + assert(total == 2) + assert(capTaken) } } `), @@ -3849,7 +3852,7 @@ func TestRuntimeStorageIteration(t *testing.T) { ) require.NoError(t, err) - // 2) Iterate through private paths + // 2) Iterate through storage paths err = runtime.ExecuteTransaction( Script{ @@ -3859,16 +3862,185 @@ func TestRuntimeStorageIteration(t *testing.T) { transaction { prepare(account: AuthAccount) { var total = 0 - account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { - var cap = account.getCapability<&AnyResource{Foo.Collection}>(path) - cap.check() + + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + account.check<[{Foo.Collection}]>(from: path) total = total + 1 return true }) + assert(total == 2) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + }) + + t.Run("broken impl, published with interface", func(t *testing.T) { + + t.Parallel() + + runtime := newTestInterpreterRuntime() + address := common.MustBytesToAddress([]byte{0x1}) + accountCodes := map[common.Location][]byte{} + ledger := newTestLedger(nil, nil) + nextTransactionLocation := newTransactionLocationGenerator() + contractIsBroken := false + + deployFoo := DeploymentTransaction("Foo", []byte(` + access(all) contract Foo { + access(all) resource interface Collection {} + } + `)) + + deployBar := DeploymentTransaction("Bar", []byte(` + import Foo from 0x1 + + access(all) contract Bar { + access(all) resource CollectionImpl: Foo.Collection {} + + access(all) fun getCollection(): @Bar.CollectionImpl { + return <- create Bar.CollectionImpl() + } + } + `)) + + newRuntimeInterface := func() Interface { + return &testRuntimeInterface{ + storage: ledger, + getSigningAccounts: func() ([]Address, error) { + return []Address{address}, nil + }, + resolveLocation: singleIdentifierLocationResolver(t), + updateAccountContractCode: func(location common.AddressLocation, code []byte) error { + accountCodes[location] = code + return nil + }, + getAccountContractCode: func(location common.AddressLocation) (code []byte, err error) { + if contractIsBroken && location.Name == "Bar" { + // Contract has a semantic error. i.e: Mismatched types at `bar` function + return []byte(` + import Foo from 0x1 + + access(all) contract Bar { + access(all) resource CollectionImpl: Foo.Collection { + access(all) var mismatch: Int + + init() { + self.mismatch = "hello" + } + } + }`), nil + } + + code = accountCodes[location] + return code, nil + }, + emitEvent: func(event cadence.Event) error { + return nil + }, + } + } + + // Deploy ``Foo` contract + + runtimeInterface := newRuntimeInterface() + + err := runtime.ExecuteTransaction( + Script{ + Source: deployFoo, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Deploy `Bar` contract + + err = runtime.ExecuteTransaction( + Script{ + Source: deployBar, + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Store values + + runtimeInterface = newRuntimeInterface() + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Bar from 0x1 + import Foo from 0x1 + + transaction { + prepare(signer: AuthAccount) { + signer.save("Hello, World!", to: /storage/first) + signer.save(<- Bar.getCollection(), to: /storage/second) + + let capA = signer.capabilities.storage.issue<&String>(/storage/first) + signer.capabilities.publish(capA, at: /public/a) + + let capB = signer.capabilities.storage.issue<&{Foo.Collection}>(/storage/second) + signer.capabilities.publish(capB, at: /public/b) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // Make the `Bar` contract broken. i.e: `Bar.CollectionImpl` type is broken. + contractIsBroken = true + + runtimeInterface = newRuntimeInterface() + + // 1) Iterate through public paths + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + var capTaken = false + + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + total = total + 1 + + if var cap = account.capabilities.get<&{Foo.Collection}>(path) { + cap.check() + capTaken = true + } + + return true + }) + // Total values iterated should be 1. // The broken value must be skipped. assert(total == 1) + + // Should not reach this path, because the iteration skip the value altogether. + assert(!capTaken) } } `), @@ -3880,7 +4052,7 @@ func TestRuntimeStorageIteration(t *testing.T) { ) require.NoError(t, err) - // 3) Iterate through storage paths + // 2) Iterate through storage paths err = runtime.ExecuteTransaction( Script{ @@ -3890,8 +4062,10 @@ func TestRuntimeStorageIteration(t *testing.T) { transaction { prepare(account: AuthAccount) { var total = 0 + var capTaken = false + account.forEachStored(fun (path: StoragePath, type: Type): Bool { - account.check<@AnyResource{Foo.Collection}>(from: path) + account.check<@{Foo.Collection}>(from: path) total = total + 1 return true }) @@ -3911,7 +4085,7 @@ func TestRuntimeStorageIteration(t *testing.T) { require.NoError(t, err) }) - t.Run("linked with wrong type", func(t *testing.T) { + t.Run("published with wrong type", func(t *testing.T) { t.Parallel() @@ -4022,8 +4196,11 @@ func TestRuntimeStorageIteration(t *testing.T) { signer.save("Hello, World!", to: /storage/first) signer.save(<- Bar.getCollection(), to: /storage/second) - signer.link<&String>(/private/a, target:/storage/first) - signer.link<&String>(/private/b, target:/storage/second) + let capA = signer.capabilities.storage.issue<&String>(/storage/first) + signer.capabilities.publish(capA, at: /public/a) + + let capB = signer.capabilities.storage.issue<&String>(/storage/second) + signer.capabilities.publish(capB, at: /public/b) } } `), @@ -4043,7 +4220,7 @@ func TestRuntimeStorageIteration(t *testing.T) { // Iterate through public paths // If the type is broken, iterator should only find 1 value. - // Otherwise, it should fin all values (2). + // Otherwise, it should find all values (2). count := 2 if brokenType { count = 1 @@ -4057,8 +4234,8 @@ func TestRuntimeStorageIteration(t *testing.T) { transaction { prepare(account: AuthAccount) { var total = 0 - account.forEachPrivate(fun (path: PrivatePath, type: Type): Bool { - var cap = account.getCapability<&String>(path) + account.forEachPublic(fun (path: PublicPath, type: Type): Bool { + var cap = account.capabilities.get<&String>(path)! cap.check() total = total + 1 return true