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 98456f56c3..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 }} @@ -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 eeeed81ab4..ddf30a4a1b 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 }} @@ -40,7 +40,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 @@ -65,7 +65,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 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.cap b/go.cap index c54c21c9f9..be63e43a0e 100644 --- a/go.cap +++ b/go.cap @@ -13,3 +13,4 @@ github.com/texttheater/golang-levenshtein/levenshtein (file) github.com/zeebo/blake3/internal/consts (file) golang.org/x/sys/unix (runtime, syscall) golang.org/x/xerrors (runtime) +github.com/onflow/cadence/runtime/interpreter (runtime) diff --git a/go.mod b/go.mod index 52669fba70..7fd96b164e 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.2.2 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/runtime/environment.go b/runtime/environment.go index bedc5e2e0b..03489eff55 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -424,6 +424,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 } } @@ -553,6 +557,11 @@ func (e *interpreterEnvironment) getProgram( if panicErr != nil { return nil, panicErr } + + if err != nil { + err = interpreter.WrappedExternalError(err) + } + return }) }) @@ -570,6 +579,11 @@ func (e *interpreterEnvironment) getCode(location common.Location) (code []byte, code, err = e.runtimeInterface.GetCode(location) }) } + + if err != nil { + err = interpreter.WrappedExternalError(err) + } + return } @@ -738,6 +752,10 @@ func (e *interpreterEnvironment) newUUIDHandler() interpreter.UUIDHandlerFunc { errors.WrapPanic(func() { uuid, err = e.runtimeInterface.GenerateUUID() }) + + if err != nil { + err = interpreter.WrappedExternalError(err) + } return } } @@ -914,7 +932,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 18c1841934..b889a3be8f 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" @@ -959,3 +960,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/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 3b1f2a90b0..8bbe9d7f76 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -513,20 +513,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 { @@ -556,6 +544,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[:] } @@ -4024,12 +4037,18 @@ 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. + // Perform a forced value de-referencing to see if the associated type is not broken. // If broken, skip this value from the iteration. - typeError := inter.checkTypeLoading(staticType) - if typeError != nil { + valueError := inter.checkValue( + value, + staticType, + invocation.LocationRange, + ) + + if valueError != nil { continue } @@ -4079,14 +4098,19 @@ func (interpreter *Interpreter) newStorageIterationFunction( ) } -func (interpreter *Interpreter) checkTypeLoading(staticType StaticType) (typeError error) { +func (interpreter *Interpreter) checkValue( + value Value, + staticType StaticType, + locationRange LocationRange, +) (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() @@ -4097,8 +4121,43 @@ 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 (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/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. diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go index e32e3c7d2c..9a290a02fc 100644 --- a/runtime/interpreter/value.go +++ b/runtime/interpreter/value.go @@ -253,9 +253,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 } @@ -266,24 +270,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, + }) } } } @@ -669,7 +681,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()) @@ -678,7 +690,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()) @@ -687,7 +699,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()) @@ -696,7 +708,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()) @@ -863,7 +875,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()) @@ -871,7 +883,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()) @@ -879,7 +891,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()) @@ -887,7 +899,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()) @@ -1094,9 +1106,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, }) } @@ -1107,9 +1120,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, }) } @@ -1120,9 +1134,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, }) } @@ -1133,9 +1148,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, }) } @@ -3173,7 +3189,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()) } @@ -3205,7 +3223,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), @@ -3219,9 +3237,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, }) } @@ -3240,9 +3259,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, }) } }() @@ -3254,9 +3274,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, }) } @@ -3275,9 +3296,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, }) } }() @@ -3289,9 +3311,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, }) } @@ -3302,7 +3325,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) }, @@ -3313,9 +3338,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, }) } @@ -3334,9 +3360,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, }) } }() @@ -3348,9 +3375,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, }) } @@ -3361,7 +3389,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) }, @@ -3373,9 +3403,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, }) } }() @@ -3387,9 +3418,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, }) } @@ -3401,9 +3433,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, }) } @@ -3415,9 +3448,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, }) } @@ -3430,9 +3464,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, }) } @@ -3472,9 +3507,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, }) } @@ -3492,9 +3528,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, }) } @@ -3512,9 +3549,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, }) } @@ -3532,18 +3570,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( @@ -3560,18 +3603,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( @@ -3718,14 +3766,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 { @@ -3739,17 +3789,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 { @@ -3763,9 +3818,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, }) } @@ -3786,17 +3842,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 { @@ -3810,9 +3871,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, }) } @@ -3833,15 +3895,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 { @@ -3855,9 +3920,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, }) } @@ -3866,24 +3932,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, + }) } } } @@ -3899,9 +3973,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, }) } @@ -3943,18 +4018,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 { @@ -3968,9 +4048,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, }) } @@ -3978,7 +4059,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 } @@ -3992,9 +4075,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, }) } @@ -4005,9 +4089,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, }) } @@ -4018,9 +4103,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, }) } @@ -4031,9 +4117,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, }) } @@ -4064,18 +4151,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) @@ -4091,9 +4186,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, }) } @@ -4108,9 +4204,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, }) } @@ -4125,9 +4222,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, }) } @@ -4142,9 +4240,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, }) } @@ -4159,9 +4258,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, }) } @@ -4307,14 +4407,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 { @@ -4328,17 +4430,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 { @@ -4352,9 +4459,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, }) } @@ -4375,17 +4483,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 { @@ -4399,9 +4512,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, }) } @@ -4422,15 +4536,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 { @@ -4444,9 +4561,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, }) } @@ -4455,24 +4573,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, + }) } } } @@ -4488,9 +4614,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, }) } @@ -4531,18 +4658,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 { @@ -4556,9 +4688,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, }) } @@ -4566,7 +4699,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 } @@ -4580,9 +4715,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, }) } @@ -4593,9 +4729,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, }) } @@ -4606,9 +4743,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, }) } @@ -4619,9 +4757,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, }) } @@ -4652,18 +4791,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) @@ -4679,9 +4826,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, }) } @@ -4696,9 +4844,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, }) } @@ -4713,9 +4862,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, }) } @@ -4730,9 +4880,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, }) } @@ -4747,9 +4898,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, }) } @@ -4897,14 +5049,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 { @@ -4918,17 +5072,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 { @@ -4942,9 +5101,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, }) } @@ -4965,17 +5125,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 { @@ -4989,9 +5154,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, }) } @@ -5012,15 +5178,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 { @@ -5034,9 +5203,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, }) } @@ -5045,24 +5215,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, + }) } } } @@ -5078,9 +5256,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, }) } @@ -5121,18 +5300,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 { @@ -5146,9 +5330,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, }) } @@ -5156,7 +5341,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 } @@ -5171,9 +5358,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, }) } @@ -5184,9 +5372,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, }) } @@ -5197,9 +5386,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, }) } @@ -5210,9 +5400,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, }) } @@ -5242,18 +5433,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) @@ -5269,9 +5468,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, }) } @@ -5286,9 +5486,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, }) } @@ -5303,9 +5504,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, }) } @@ -5320,9 +5522,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, }) } @@ -5337,9 +5540,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, }) } @@ -5485,14 +5689,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 { @@ -5505,9 +5711,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 } @@ -5516,9 +5726,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, }) } @@ -5533,9 +5744,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, }) } @@ -5556,17 +5768,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 { @@ -5580,9 +5797,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, }) } @@ -5603,15 +5821,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 { @@ -5625,9 +5846,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, }) } @@ -5636,24 +5858,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, + }) } } } @@ -5669,9 +5899,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, }) } @@ -5712,18 +5943,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 { @@ -5737,9 +5973,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, }) } @@ -5747,7 +5984,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 } @@ -5761,9 +6000,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, }) } @@ -5774,9 +6014,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, }) } @@ -5787,9 +6028,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, }) } @@ -5801,9 +6043,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, }) } @@ -5833,9 +6076,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() @@ -5855,9 +6102,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, }) } @@ -5872,9 +6120,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, }) } @@ -5889,9 +6138,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, }) } @@ -5906,9 +6156,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, }) } @@ -5923,9 +6174,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, }) } @@ -6072,7 +6324,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()) } @@ -6110,7 +6364,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 { @@ -6124,9 +6380,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, }) } @@ -6146,9 +6403,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 @@ -6161,9 +6422,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, }) } @@ -6198,9 +6460,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, }) } @@ -6220,9 +6483,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 @@ -6235,9 +6502,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, }) } @@ -6272,9 +6540,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, }) } @@ -6282,7 +6551,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) @@ -6296,9 +6567,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, }) } @@ -6306,9 +6578,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 @@ -6321,9 +6597,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, }) } @@ -6346,9 +6623,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, }) } @@ -6361,11 +6639,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) @@ -6379,9 +6661,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, }) } @@ -6394,7 +6677,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) { @@ -6412,9 +6697,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, }) } @@ -6426,9 +6712,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, }) } @@ -6440,9 +6727,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, }) } @@ -6454,9 +6742,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, }) } @@ -6508,9 +6797,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 @@ -6523,9 +6816,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, }) } @@ -6542,9 +6836,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, }) } @@ -6561,9 +6856,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, }) } @@ -6580,17 +6876,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 { @@ -6606,17 +6907,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 { @@ -6762,7 +7068,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()) } @@ -6800,7 +7108,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 { @@ -6814,9 +7124,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, }) } @@ -6836,9 +7147,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 @@ -6851,9 +7166,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, }) } @@ -6888,9 +7204,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, }) } @@ -6910,9 +7227,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 @@ -6925,9 +7246,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, }) } @@ -6962,9 +7284,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, }) } @@ -6972,7 +7295,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) @@ -6986,9 +7311,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, }) } @@ -6996,9 +7322,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 @@ -7011,9 +7341,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, }) } @@ -7036,9 +7367,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, }) } @@ -7051,11 +7383,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 @@ -7068,9 +7404,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, }) } @@ -7083,7 +7420,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) { @@ -7100,9 +7439,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, }) } @@ -7114,9 +7454,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, }) } @@ -7128,9 +7469,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, }) } @@ -7142,9 +7484,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, }) } @@ -7196,9 +7539,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 @@ -7211,9 +7558,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, }) } @@ -7230,9 +7578,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, }) } @@ -7249,9 +7598,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, }) } @@ -7268,19 +7618,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())) @@ -7294,19 +7649,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 @@ -7436,7 +7796,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 }, @@ -7445,7 +7807,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, @@ -7486,7 +7850,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()) } @@ -7526,9 +7892,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, }) } @@ -7547,9 +7914,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, }) } }() @@ -7561,9 +7929,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, }) } @@ -7575,7 +7944,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 }, @@ -7586,9 +7957,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, }) } @@ -7611,9 +7983,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, }) } @@ -7624,7 +7997,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 @@ -7636,9 +8011,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, }) } @@ -7657,9 +8033,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, }) } }() @@ -7671,9 +8048,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, }) } @@ -7684,7 +8062,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) }, @@ -7696,9 +8076,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, }) } }() @@ -7710,9 +8091,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, }) } @@ -7724,9 +8106,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, }) } @@ -7738,9 +8121,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, }) } @@ -7752,9 +8136,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, }) } @@ -7794,9 +8179,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, }) } @@ -7814,9 +8200,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, }) } @@ -7834,9 +8221,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, }) } @@ -7854,18 +8242,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( @@ -7883,17 +8276,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( @@ -8039,7 +8437,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) } @@ -8051,9 +8449,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, }) } @@ -8061,7 +8460,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) }) @@ -8071,9 +8472,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, }) } @@ -8091,9 +8493,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, }) } @@ -8103,7 +8506,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) }, @@ -8114,9 +8519,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, }) } @@ -8137,9 +8543,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, }) } @@ -8147,7 +8554,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) }, @@ -8158,9 +8567,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, }) } @@ -8169,7 +8579,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) }, @@ -8180,9 +8592,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, }) } @@ -8202,9 +8615,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, }) } @@ -8212,7 +8626,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) }, @@ -8224,9 +8640,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, }) } }() @@ -8238,9 +8655,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, }) } @@ -8251,9 +8669,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, }) } @@ -8264,9 +8683,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, }) } @@ -8277,9 +8697,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, }) } @@ -8314,18 +8735,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) @@ -8370,9 +8799,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, }) } @@ -8388,9 +8818,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, }) } @@ -8406,9 +8837,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, }) } @@ -8424,9 +8856,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, }) } @@ -8442,9 +8875,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, }) } @@ -8589,7 +9023,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 { @@ -8600,9 +9034,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, }) } @@ -8612,7 +9047,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) }, @@ -8623,9 +9060,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, }) } @@ -8646,9 +9084,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, }) } @@ -8658,7 +9097,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) }, @@ -8669,9 +9110,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, }) } @@ -8692,9 +9134,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, }) } @@ -8702,7 +9145,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) }, @@ -8713,9 +9158,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, }) } @@ -8724,7 +9170,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) }, @@ -8735,9 +9183,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, }) } @@ -8757,9 +9206,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, }) } @@ -8767,7 +9217,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) }, @@ -8779,9 +9231,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, }) } }() @@ -8793,9 +9246,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, }) } @@ -8806,9 +9260,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, }) } @@ -8819,9 +9274,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, }) } @@ -8832,9 +9288,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, }) } @@ -8877,9 +9334,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, }) } @@ -8895,9 +9353,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, }) } @@ -8913,9 +9372,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, }) } @@ -8931,9 +9391,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, }) } @@ -8949,9 +9410,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, }) } @@ -9102,7 +9564,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) } @@ -9114,9 +9576,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, }) } @@ -9126,7 +9589,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) }, @@ -9137,9 +9602,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, }) } @@ -9160,9 +9626,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, }) } @@ -9172,7 +9639,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) }, @@ -9183,9 +9652,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, }) } @@ -9206,9 +9676,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, }) } @@ -9216,7 +9687,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) }, @@ -9227,9 +9700,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, }) } @@ -9237,7 +9711,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) }, @@ -9248,9 +9724,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, }) } @@ -9271,9 +9748,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, }) } @@ -9281,7 +9759,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) }, @@ -9293,9 +9773,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, }) } }() @@ -9307,9 +9788,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, }) } @@ -9320,9 +9802,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, }) } @@ -9333,9 +9816,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, }) } @@ -9346,9 +9830,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, }) } @@ -9391,9 +9876,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, }) } @@ -9409,9 +9895,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, }) } @@ -9427,9 +9914,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, }) } @@ -9445,9 +9933,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, }) } @@ -9463,9 +9952,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, }) } @@ -9624,7 +10114,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) } @@ -9652,7 +10144,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 } @@ -9661,9 +10155,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, }) } @@ -9679,9 +10174,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, }) } @@ -9702,9 +10198,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, }) } @@ -9714,7 +10211,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) }, @@ -9725,9 +10224,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, }) } @@ -9748,9 +10248,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, }) } @@ -9758,7 +10259,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) }, @@ -9769,9 +10272,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, }) } @@ -9779,7 +10283,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) }, @@ -9790,9 +10296,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, }) } @@ -9812,9 +10319,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, }) } @@ -9822,7 +10330,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) }, @@ -9834,9 +10344,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, }) } }() @@ -9848,9 +10359,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, }) } @@ -9861,9 +10373,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, }) } @@ -9874,9 +10387,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, }) } @@ -9887,9 +10401,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, }) } @@ -9932,9 +10447,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, }) } @@ -9950,9 +10466,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, }) } @@ -9968,9 +10485,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, }) } @@ -9986,9 +10504,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, }) } @@ -10004,9 +10523,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, }) } @@ -10158,7 +10678,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()) } @@ -10198,9 +10720,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, }) } @@ -10220,7 +10743,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 }, @@ -10231,9 +10756,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, }) } @@ -10264,9 +10790,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, }) } @@ -10286,7 +10813,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 }, @@ -10297,9 +10826,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, }) } @@ -10330,9 +10860,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, }) } @@ -10341,7 +10872,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) }, @@ -10352,9 +10885,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, }) } @@ -10364,7 +10898,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 }, @@ -10375,9 +10911,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, }) } @@ -10398,9 +10935,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, }) } @@ -10409,7 +10947,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) }, @@ -10422,9 +10962,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, }) } }() @@ -10436,9 +10977,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, }) } @@ -10450,9 +10992,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, }) } @@ -10464,9 +11007,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, }) } @@ -10478,9 +11022,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, }) } @@ -10535,9 +11080,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 @@ -10549,9 +11098,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, }) } @@ -10568,9 +11118,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, }) } @@ -10587,9 +11138,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, }) } @@ -10607,9 +11159,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, }) } @@ -10618,10 +11171,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())) }, @@ -10632,9 +11189,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, }) } @@ -10643,10 +11201,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())) }, @@ -10791,7 +11353,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()) @@ -10832,9 +11396,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, }) } @@ -10854,7 +11419,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 }, @@ -10866,9 +11433,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, }) } @@ -10899,9 +11467,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, }) } @@ -10921,7 +11490,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 }, @@ -10932,9 +11503,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, }) } @@ -10966,9 +11538,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, }) } @@ -10977,7 +11550,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) }, @@ -10988,9 +11563,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, }) } @@ -11000,7 +11576,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 }, @@ -11011,9 +11589,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, }) } @@ -11034,9 +11613,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, }) } @@ -11045,7 +11625,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) }, @@ -11057,9 +11639,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, }) } }() @@ -11071,9 +11654,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, }) } @@ -11085,9 +11669,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, }) } @@ -11099,9 +11684,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, }) } @@ -11113,9 +11699,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, }) } @@ -11169,9 +11756,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 @@ -11183,9 +11774,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, }) } @@ -11202,9 +11794,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, }) } @@ -11221,9 +11814,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, }) } @@ -11240,9 +11834,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, }) } @@ -11251,10 +11846,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())) }, @@ -11265,9 +11864,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, }) } @@ -11276,10 +11876,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())) }, @@ -11424,7 +12028,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) } @@ -11436,9 +12040,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, }) } @@ -11457,9 +12062,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, }) } @@ -11478,14 +12084,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 { @@ -11499,9 +12108,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, }) } @@ -11520,14 +12130,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 { @@ -11545,9 +12158,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, }) } @@ -11558,9 +12172,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, }) } @@ -11571,9 +12186,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, }) } @@ -11584,9 +12200,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, }) } @@ -11623,9 +12240,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, }) } @@ -11640,9 +12258,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, }) } @@ -11657,9 +12276,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, }) } @@ -11674,9 +12294,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, }) } @@ -11691,9 +12312,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, }) } @@ -11843,7 +12465,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 { @@ -11854,9 +12476,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, }) } @@ -11875,9 +12498,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, }) } @@ -11896,14 +12520,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 { @@ -11917,9 +12544,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, }) } @@ -11938,14 +12566,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 { @@ -11963,9 +12594,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, }) } @@ -11976,9 +12608,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, }) } @@ -11989,9 +12622,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, }) } @@ -12002,9 +12636,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, }) } @@ -12041,9 +12676,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, }) } @@ -12058,9 +12694,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, }) } @@ -12075,9 +12712,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, }) } @@ -12092,9 +12730,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, }) } @@ -12109,9 +12748,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, }) } @@ -12263,7 +12903,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) } @@ -12275,9 +12915,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, }) } @@ -12296,9 +12937,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, }) } @@ -12317,14 +12959,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 { @@ -12338,9 +12983,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, }) } @@ -12359,14 +13005,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 { @@ -12384,9 +13033,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, }) } @@ -12397,9 +13047,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, }) } @@ -12410,9 +13061,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, }) } @@ -12423,9 +13075,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, }) } @@ -12462,9 +13115,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, }) } @@ -12479,9 +13133,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, }) } @@ -12496,9 +13151,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, }) } @@ -12513,9 +13169,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, }) } @@ -12530,9 +13187,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, }) } @@ -12692,7 +13350,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) } @@ -12720,9 +13380,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, }) } @@ -12741,9 +13402,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, }) } @@ -12762,14 +13424,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 { @@ -12783,9 +13448,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, }) } @@ -12804,14 +13470,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 { @@ -12829,9 +13498,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, }) } @@ -12842,9 +13512,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, }) } @@ -12855,9 +13526,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, }) } @@ -12868,9 +13540,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, }) } @@ -12907,9 +13580,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, }) } @@ -12924,9 +13598,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, }) } @@ -12941,9 +13616,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, }) } @@ -12958,9 +13634,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, }) } @@ -12975,9 +13652,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, }) } @@ -13128,7 +13806,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()) } @@ -13168,9 +13848,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, }) } @@ -13201,7 +13882,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()) } @@ -13209,9 +13890,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, }) } @@ -13242,7 +13924,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()) } @@ -13250,9 +13932,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, }) } @@ -13261,7 +13944,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) }, @@ -13272,9 +13957,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, }) } @@ -13291,7 +13977,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()) } @@ -13299,9 +13985,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, }) } @@ -13310,7 +13997,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) }, @@ -13318,7 +14007,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()) } @@ -13326,9 +14015,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, }) } @@ -13340,9 +14030,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, }) } @@ -13354,9 +14045,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, }) } @@ -13368,9 +14060,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, }) } @@ -13439,9 +14132,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, }) } @@ -13458,9 +14152,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, }) } @@ -13477,9 +14172,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, }) } @@ -13497,9 +14193,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, }) } @@ -13508,10 +14205,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())) }, @@ -13533,10 +14234,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())) }, @@ -13681,7 +14386,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()) } @@ -13721,9 +14428,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, }) } @@ -13754,7 +14462,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()) } @@ -13762,9 +14470,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, }) } @@ -13795,7 +14504,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()) } @@ -13803,9 +14512,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, }) } @@ -13814,7 +14524,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) }, @@ -13825,9 +14537,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, }) } @@ -13844,7 +14557,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()) } @@ -13852,9 +14565,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, }) } @@ -13863,7 +14577,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) }, @@ -13871,7 +14587,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()) } @@ -13879,9 +14595,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, }) } @@ -13893,9 +14610,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, }) } @@ -13907,9 +14625,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, }) } @@ -13921,9 +14640,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, }) } @@ -13992,9 +14712,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, }) } @@ -14011,9 +14732,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, }) } @@ -14030,9 +14752,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, }) } @@ -14050,9 +14773,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, }) } @@ -14061,10 +14785,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())) }, @@ -14075,9 +14803,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, }) } @@ -14086,10 +14815,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())) }, @@ -14196,11 +14929,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) @@ -14260,14 +14997,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 { @@ -14281,9 +15020,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, }) } @@ -14298,9 +15038,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, }) } @@ -14321,18 +15062,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) @@ -14345,9 +15091,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, }) } @@ -14371,9 +15118,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, }) } @@ -14385,9 +15133,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() @@ -14400,9 +15152,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, }) } @@ -14429,9 +15182,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, }) } @@ -14443,9 +15197,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() @@ -14458,9 +15216,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, }) } @@ -14487,9 +15246,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, }) } @@ -14497,9 +15257,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, }) } @@ -14521,9 +15282,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, }) } @@ -14534,9 +15296,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, }) } @@ -14547,9 +15310,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, }) } @@ -14560,9 +15324,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, }) } @@ -14593,7 +15358,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, @@ -14611,7 +15378,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() @@ -14737,7 +15506,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) @@ -14797,7 +15568,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) } @@ -14809,9 +15580,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, }) } @@ -14826,9 +15598,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, }) } @@ -14848,9 +15621,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, }) } @@ -14859,7 +15633,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) } @@ -14871,9 +15647,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, }) } @@ -14894,9 +15671,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, }) } @@ -14908,7 +15686,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() @@ -14921,9 +15701,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, }) } @@ -14948,9 +15729,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, }) } @@ -14972,9 +15754,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, }) } }() @@ -14986,9 +15769,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, }) } @@ -14996,9 +15780,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, }) } @@ -15020,9 +15805,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, }) } @@ -15033,9 +15819,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, }) } @@ -15046,9 +15833,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, }) } @@ -15059,9 +15847,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, }) } @@ -15092,7 +15881,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, @@ -15106,7 +15897,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. @@ -15114,7 +15907,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() @@ -15127,7 +15922,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) @@ -15490,7 +16287,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, @@ -15635,7 +16432,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, nil) } @@ -16047,7 +16844,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 } @@ -16555,7 +17352,7 @@ func NewEnumCaseValue( return v } -func (v *CompositeValue) getBaseValue(interpreter *Interpreter, locationRange LocationRange) *EphemeralReferenceValue { +func (v *CompositeValue) getBaseValue() *EphemeralReferenceValue { return v.base } @@ -16680,10 +17477,9 @@ func attachmentBaseAuthorization( func attachmentBaseAndSelfValues( interpreter *Interpreter, - locationRange LocationRange, v *CompositeValue, ) (base *EphemeralReferenceValue, self *EphemeralReferenceValue) { - base = v.getBaseValue(interpreter, locationRange) + base = v.getBaseValue() attachmentType := interpreter.MustSemaTypeOfValue(v).(*sema.CompositeType) @@ -19162,8 +19958,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 1a3278e6ba..06e0e0da87 100644 --- a/runtime/literal.go +++ b/runtime/literal.go @@ -108,7 +108,7 @@ func ParseLiteralArgumentList( value, err := LiteralValue(inter, argument.Expression, parameterType) if err != nil { return nil, parser.NewSyntaxError( - ast.Position{Line: 1}, + argument.Expression.StartPosition(), "invalid argument at index %d: %v", i, err, ) } diff --git a/runtime/runtime.go b/runtime/runtime.go index 4c83a29282..675f46f191 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -259,6 +259,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 2354568a0a..a54aaa0290 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -7651,7 +7651,7 @@ func assertRuntimeErrorIsInternalError(t *testing.T, err error) { require.True( t, runtimeErrors.IsInternalError(innerError), - "Expected `UserError`, found `%T`", innerError, + "Expected `InternalError`, found `%T`", innerError, ) } @@ -8944,3 +8944,314 @@ func TestRuntimeReturnDestroyedOptional(t *testing.T) { RequireError(t, err) 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() {} + + access(all) 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() {} + + access(all) 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() {} + + access(all) 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() {} + + access(all) 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) + }) +} + +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) + let cap = signer.capabilities.storage.issue<&Foo.R>(/storage/r) + signer.capabilities.publish(cap, at: /public/r) + } + } + `) + + tx2 := []byte(` + transaction { + prepare(signer: AuthAccount) { + let cap = signer.capabilities.get<&AnyStruct>(/public/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) +} diff --git a/runtime/sema/check_reference_expression.go b/runtime/sema/check_reference_expression.go index a18e5f3e81..16092129b5 100644 --- a/runtime/sema/check_reference_expression.go +++ b/runtime/sema/check_reference_expression.go @@ -93,7 +93,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/stdlib/account.go b/runtime/stdlib/account.go index 665b474f3b..ae1553e427 100644 --- a/runtime/stdlib/account.go +++ b/runtime/stdlib/account.go @@ -123,7 +123,7 @@ func NewAuthAccountConstructor(creator AccountCreator) StandardLibraryValue { address, err = creator.CreateAccount(payerAddress) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -341,7 +341,7 @@ func newAccountBalanceGetFunction( balance, err = provider.GetAccountBalance(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -370,7 +370,7 @@ func newAccountAvailableBalanceGetFunction( balance, err = provider.GetAccountAvailableBalance(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return @@ -409,7 +409,7 @@ func newStorageUsedGetFunction( capacity, err = provider.GetStorageUsed(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return capacity }, @@ -448,7 +448,7 @@ func newStorageCapacityGetFunction( capacity, err = provider.GetStorageCapacity(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return capacity }, @@ -505,7 +505,7 @@ func newAccountKeysAddFunction( accountKey, err = handler.AddAccountKey(address, publicKey, hashAlgo, weight) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } handler.EmitEvent( @@ -576,7 +576,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. @@ -660,7 +660,7 @@ func newAccountKeysForEachFunction( }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } var accountKey *AccountKey @@ -670,7 +670,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. @@ -724,7 +724,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 @@ -768,7 +768,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. @@ -1136,7 +1136,7 @@ func newAccountContractsGetNamesFunction( names, err = provider.GetAccountContractNames(address) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } values := make([]interpreter.Value, len(names)) @@ -1201,7 +1201,7 @@ func newAccountContractsGetFunction( code, err = provider.GetAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if len(code) > 0 { @@ -1267,7 +1267,7 @@ func newAccountContractsBorrowFunction( code, err = handler.GetAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } if len(code) == 0 { return interpreter.Nil @@ -1709,7 +1709,7 @@ func updateAccountContractCode( err = handler.UpdateAccountContractCode(location, code) }) if err != nil { - return err + return interpreter.WrappedExternalError(err) } if createContract { @@ -1866,7 +1866,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, @@ -1894,7 +1894,7 @@ func newAuthAccountContractsRemoveFunction( err = handler.RemoveAccountContractCode(location) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } // NOTE: the contract recording function delays the write @@ -2423,7 +2423,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")) @@ -2505,7 +2505,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 c893533d14..2f8c69be2f 100644 --- a/runtime/stdlib/block.go +++ b/runtime/stdlib/block.go @@ -179,7 +179,7 @@ func getBlockAtHeight( block, exists, err = provider.GetBlockAtHeight(height) }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return block, exists @@ -204,7 +204,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 bdd4280310..b5ab78823a 100644 --- a/runtime/stdlib/log.go +++ b/runtime/stdlib/log.go @@ -61,7 +61,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 4b86b388de..ef27bebc3a 100644 --- a/runtime/stdlib/publickey.go +++ b/runtime/stdlib/publickey.go @@ -68,6 +68,9 @@ func newPublicKeyValidationHandler(validator PublicKeyValidator) interpreter.Pub errors.WrapPanic(func() { err = validator.ValidatePublicKey(publicKey) }) + if err != nil { + err = interpreter.WrappedExternalError(err) + } return err } } @@ -291,7 +294,7 @@ func newPublicKeyVerifySignatureFunction( }) if err != nil { - panic(err) + panic(interpreter.WrappedExternalError(err)) } return interpreter.AsBoolValue(valid) @@ -344,7 +347,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 12bb5f3e11..a01279c70a 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) } } diff --git a/runtime/storage_test.go b/runtime/storage_test.go index c3516f94ac..e66bd0d845 100644 --- a/runtime/storage_test.go +++ b/runtime/storage_test.go @@ -3687,6 +3687,584 @@ func TestRuntimeStorageIteration(t *testing.T) { ) require.NoError(t, err) }) + + t.Run("broken impl, stored 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) struct interface Collection {} + } + `)) + + deployBar := DeploymentTransaction("Bar", []byte(` + import Foo from 0x1 + + access(all) contract Bar { + access(all) struct CollectionImpl: Foo.Collection {} + } + `)) + + 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) struct 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) + + 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) + + 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() + var refArray = cap.borrow()! + capTaken = true + } + + return true + }) + + assert(total == 2) + assert(capTaken) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // 2) 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<[{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) + } + } + `), + }, + Context{ + Interface: runtimeInterface, + Location: nextTransactionLocation(), + }, + ) + require.NoError(t, err) + + // 2) Iterate through storage paths + + err = runtime.ExecuteTransaction( + Script{ + Source: []byte(` + import Foo from 0x1 + + transaction { + prepare(account: AuthAccount) { + var total = 0 + var capTaken = false + + account.forEachStored(fun (path: StoragePath, type: Type): Bool { + account.check<@{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("published 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(` + 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<&String>(/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 = brokenType + + runtimeInterface = newRuntimeInterface() + + // Iterate through public paths + + // If the type is broken, iterator should only find 1 value. + // Otherwise, it should find 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.forEachPublic(fun (path: PublicPath, type: Type): Bool { + var cap = account.capabilities.get<&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) + }) + }) } func TestRuntimeStorageIteration2(t *testing.T) { diff --git a/runtime/tests/checker/reference_test.go b/runtime/tests/checker/reference_test.go index 809a461135..e804153e9f 100644 --- a/runtime/tests/checker/reference_test.go +++ b/runtime/tests/checker/reference_test.go @@ -2812,3 +2812,40 @@ func TestCheckResourceReferenceMethodInvocationAfterMove(t *testing.T) { invalidatedRefError := &sema.InvalidatedResourceReferenceError{} assert.ErrorAs(t, errs[0], &invalidatedRefError) } + +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) + }) +} diff --git a/runtime/tests/interpreter/memory_metering_test.go b/runtime/tests/interpreter/memory_metering_test.go index 704849831b..a730812261 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 e4c7b32af6..2289379cb1 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,149 +1126,174 @@ 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 IDCapability: + 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 randomValueKindIDCapability: return interpreter.NewUnmeteredIDCapabilityValue( - interpreter.UInt64Value(randomInt(math.MaxInt-1)), - randomAddressValue(), + interpreter.UInt64Value(r.randomInt(math.MaxInt-1)), + r.randomAddressValue(), interpreter.ReferenceStaticType{ Authorization: interpreter.UnauthorizedAccess, ReferencedType: 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, } @@ -1302,27 +1325,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], @@ -1330,17 +1353,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 } @@ -1357,16 +1380,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) } @@ -1381,181 +1404,134 @@ 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?` - IDCapability + // Non-hashable values + randomValueKindVoid + randomValueKindNil // `Never?` + 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 @@ -1626,13 +1602,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), "$") -} diff --git a/runtime/tests/utils/utils.go b/runtime/tests/utils/utils.go index c4be92a241..1a03296ca8 100644 --- a/runtime/tests/utils/utils.go +++ b/runtime/tests/utils/utils.go @@ -29,8 +29,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" ) @@ -212,6 +214,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() @@ -221,6 +233,10 @@ 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("") + } } func ArrayElements(inter *interpreter.Interpreter, array *interpreter.ArrayValue) []interpreter.Value { 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 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"