From 2a28498936530e54890f279c6162b91800ae45f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 5 Oct 2020 10:50:01 -0700 Subject: [PATCH] refactor interpreter errors to non-pointer values --- runtime/interpreter/errors.go | 42 ++++----- runtime/interpreter/interpreter.go | 28 +++--- runtime/interpreter/value.go | 22 ++--- runtime/runtime_test.go | 2 +- runtime/tests/interpreter/account_test.go | 30 +++---- runtime/tests/interpreter/capability_test.go | 12 +-- .../tests/interpreter/dynamic_casting_test.go | 28 +++--- runtime/tests/interpreter/interpreter_test.go | 90 +++++++++---------- .../tests/interpreter/transactions_test.go | 16 ++-- 9 files changed, 130 insertions(+), 140 deletions(-) diff --git a/runtime/interpreter/errors.go b/runtime/interpreter/errors.go index a2da149223..f56e108042 100644 --- a/runtime/interpreter/errors.go +++ b/runtime/interpreter/errors.go @@ -61,7 +61,7 @@ type NotDeclaredError struct { Name string } -func (e *NotDeclaredError) Error() string { +func (e NotDeclaredError) Error() string { return fmt.Sprintf( "cannot find %s in this scope: `%s`", e.ExpectedKind.Name(), @@ -69,7 +69,7 @@ func (e *NotDeclaredError) Error() string { ) } -func (e *NotDeclaredError) SecondaryError() string { +func (e NotDeclaredError) SecondaryError() string { return "not found in this scope" } @@ -79,7 +79,7 @@ type NotInvokableError struct { Value Value } -func (e *NotInvokableError) Error() string { +func (e NotInvokableError) Error() string { return fmt.Sprintf("cannot call value: %#+v", e.Value) } @@ -90,7 +90,7 @@ type ArgumentCountError struct { ArgumentCount int } -func (e *ArgumentCountError) Error() string { +func (e ArgumentCountError) Error() string { return fmt.Sprintf( "incorrect number of arguments: expected %d, got %d", e.ParameterCount, @@ -98,23 +98,13 @@ func (e *ArgumentCountError) Error() string { ) } -// InvalidParameterTypeInInvocationError - -type InvalidParameterTypeInInvocationError struct { - InvalidParameterType sema.Type -} - -func (e *InvalidParameterTypeInInvocationError) Error() string { - return fmt.Sprintf("cannot invoke functions with parameter type: `%s`", e.InvalidParameterType) -} - // TransactionNotDeclaredError type TransactionNotDeclaredError struct { Index int } -func (e *TransactionNotDeclaredError) Error() string { +func (e TransactionNotDeclaredError) Error() string { return fmt.Sprintf( "cannot find transaction with index %d in this scope", e.Index, @@ -129,7 +119,7 @@ type ConditionError struct { LocationRange } -func (e *ConditionError) Error() string { +func (e ConditionError) Error() string { if e.Message == "" { return fmt.Sprintf("%s failed", e.ConditionKind.Name()) } @@ -142,7 +132,7 @@ type RedeclarationError struct { Name string } -func (e *RedeclarationError) Error() string { +func (e RedeclarationError) Error() string { return fmt.Sprintf("cannot redeclare: `%s` is already declared", e.Name) } @@ -152,7 +142,7 @@ type DereferenceError struct { LocationRange } -func (e *DereferenceError) Error() string { +func (e DereferenceError) Error() string { return "dereference failed" } @@ -187,7 +177,7 @@ type DestroyedCompositeError struct { LocationRange } -func (e *DestroyedCompositeError) Error() string { +func (e DestroyedCompositeError) Error() string { return fmt.Sprintf("%s is destroyed and cannot be accessed anymore", e.CompositeKind.Name()) } @@ -197,7 +187,7 @@ type ForceAssignmentToNonNilResourceError struct { LocationRange } -func (e *ForceAssignmentToNonNilResourceError) Error() string { +func (e ForceAssignmentToNonNilResourceError) Error() string { return "force assignment to non-nil resource-typed value" } @@ -207,7 +197,7 @@ type ForceNilError struct { LocationRange } -func (e *ForceNilError) Error() string { +func (e ForceNilError) Error() string { return "unexpectedly found nil while forcing an Optional value" } @@ -218,7 +208,7 @@ type TypeMismatchError struct { LocationRange } -func (e *TypeMismatchError) Error() string { +func (e TypeMismatchError) Error() string { return fmt.Sprintf( "unexpectedly found non-`%s` while force-casting value", e.ExpectedType.QualifiedString(), @@ -233,11 +223,11 @@ type InvalidPathDomainError struct { LocationRange } -func (e *InvalidPathDomainError) Error() string { +func (e InvalidPathDomainError) Error() string { return "invalid path domain" } -func (e *InvalidPathDomainError) SecondaryError() string { +func (e InvalidPathDomainError) SecondaryError() string { domainNames := make([]string, len(e.ExpectedDomains)) @@ -260,7 +250,7 @@ type OverwriteError struct { LocationRange } -func (e *OverwriteError) Error() string { +func (e OverwriteError) Error() string { return fmt.Sprintf( "failed to save object: path %s in account %s already stores an object", e.Path, @@ -276,7 +266,7 @@ type CyclicLinkError struct { LocationRange } -func (e *CyclicLinkError) Error() string { +func (e CyclicLinkError) Error() string { var builder strings.Builder for i, path := range e.Paths { if i > 0 { diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index bdba8e45cb..0b5a91b645 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -719,7 +719,7 @@ func (interpreter *Interpreter) prepareInvokeVariable( // function must be defined as a global variable variable, ok := interpreter.Globals[functionName] if !ok { - return nil, &NotDeclaredError{ + return nil, NotDeclaredError{ ExpectedKind: common.DeclarationKindFunction, Name: functionName, } @@ -730,7 +730,7 @@ func (interpreter *Interpreter) prepareInvokeVariable( // the global variable must be declared as a function functionValue, ok := variableValue.(FunctionValue) if !ok { - return nil, &NotInvokableError{ + return nil, NotInvokableError{ Value: variableValue, } } @@ -741,7 +741,7 @@ func (interpreter *Interpreter) prepareInvokeVariable( invokableType, ok := ty.(sema.InvokableType) if !ok { - return nil, &NotInvokableError{ + return nil, NotInvokableError{ Value: variableValue, } } @@ -756,7 +756,7 @@ func (interpreter *Interpreter) prepareInvokeTransaction( arguments []Value, ) (trampoline Trampoline, err error) { if index >= len(interpreter.Transactions) { - return nil, &TransactionNotDeclaredError{Index: index} + return nil, TransactionNotDeclaredError{Index: index} } functionValue := interpreter.Transactions[index] @@ -787,7 +787,7 @@ func (interpreter *Interpreter) prepareInvoke( if functionType.RequiredArgumentCount == nil || argumentCount < *functionType.RequiredArgumentCount { - return nil, &ArgumentCountError{ + return nil, ArgumentCountError{ ParameterCount: parameterCount, ArgumentCount: argumentCount, } @@ -800,7 +800,7 @@ func (interpreter *Interpreter) prepareInvoke( // TODO: value type is not known, reject for now switch parameterType.(type) { case *sema.AnyStructType, *sema.AnyResourceType: - return nil, &NotInvokableError{ + return nil, NotInvokableError{ Value: functionValue, } } @@ -936,7 +936,7 @@ func (interpreter *Interpreter) functionDeclarationValue( // NOTE: consider using NewInterpreter if the value should be predefined in all programs func (interpreter *Interpreter) ImportValue(name string, value Value) error { if _, ok := interpreter.Globals[name]; ok { - return &RedeclarationError{ + return RedeclarationError{ Name: name, } } @@ -1059,7 +1059,7 @@ func (interpreter *Interpreter) visitConditions(conditions []*ast.Condition) Tra Then(func(result interface{}) { message := result.(*StringValue).Str - panic(&ConditionError{ + panic(ConditionError{ ConditionKind: condition.Kind, Message: message, LocationRange: interpreter.locationRange(condition.Test), @@ -1355,7 +1355,7 @@ func (interpreter *Interpreter) visitAssignment( if _, ok := target.(NilValue); !ok { locationRange := interpreter.locationRange(position) - panic(&ForceAssignmentToNonNilResourceError{ + panic(ForceAssignmentToNonNilResourceError{ LocationRange: locationRange, }) } @@ -3329,7 +3329,7 @@ func (interpreter *Interpreter) VisitCastingExpression(expression *ast.CastingEx case ast.OperationForceCast: if !isSubType { panic( - &TypeMismatchError{ + TypeMismatchError{ ExpectedType: expectedType, LocationRange: interpreter.locationRange(expression.Expression), }, @@ -3390,7 +3390,7 @@ func (interpreter *Interpreter) VisitForceExpression(expression *ast.ForceExpres case NilValue: panic( - &ForceNilError{ + ForceNilError{ LocationRange: interpreter.locationRange(expression.Expression), }, ) @@ -3717,7 +3717,7 @@ func mustPathDomain( } panic( - &InvalidPathDomainError{ + InvalidPathDomainError{ ActualDomain: path.Domain, ExpectedDomains: expectedDomains, LocationRange: locationRange, @@ -3758,7 +3758,7 @@ func (interpreter *Interpreter) authAccountSaveFunction(addressValue AddressValu if interpreter.storedValueExists(address, key) { panic( - &OverwriteError{ + OverwriteError{ Address: addressValue, Path: path, LocationRange: invocation.LocationRange, @@ -4143,7 +4143,7 @@ func (interpreter *Interpreter) getCapabilityFinalTargetStorageKey( // Detect cyclic links if _, ok := seenKeys[key]; ok { - panic(&CyclicLinkError{ + panic(CyclicLinkError{ Address: addressValue, Paths: paths, LocationRange: locationRange, diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go index 937968ea21..a20504f1af 100644 --- a/runtime/interpreter/value.go +++ b/runtime/interpreter/value.go @@ -5294,7 +5294,7 @@ func (v *CompositeValue) Copy() Value { func (v *CompositeValue) checkStatus(locationRange LocationRange) { if v.destroyed { - panic(&DestroyedCompositeError{ + panic(DestroyedCompositeError{ CompositeKind: v.Kind, LocationRange: locationRange, }) @@ -6026,7 +6026,7 @@ func (v *StorageReferenceValue) String() string { func (v *StorageReferenceValue) DynamicType(interpreter *Interpreter) DynamicType { referencedValue := v.referencedValue(interpreter) if referencedValue == nil { - panic(&DereferenceError{}) + panic(DereferenceError{}) } innerType := (*referencedValue).DynamicType(interpreter) @@ -6076,7 +6076,7 @@ func (v *StorageReferenceValue) referencedValue(interpreter *Interpreter) *Value func (v *StorageReferenceValue) GetMember(interpreter *Interpreter, locationRange LocationRange, name string) Value { referencedValue := v.referencedValue(interpreter) if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6087,7 +6087,7 @@ func (v *StorageReferenceValue) GetMember(interpreter *Interpreter, locationRang func (v *StorageReferenceValue) SetMember(interpreter *Interpreter, locationRange LocationRange, name string, value Value) { referencedValue := v.referencedValue(interpreter) if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6098,7 +6098,7 @@ func (v *StorageReferenceValue) SetMember(interpreter *Interpreter, locationRang func (v *StorageReferenceValue) Get(interpreter *Interpreter, locationRange LocationRange, key Value) Value { referencedValue := v.referencedValue(interpreter) if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6110,7 +6110,7 @@ func (v *StorageReferenceValue) Get(interpreter *Interpreter, locationRange Loca func (v *StorageReferenceValue) Set(interpreter *Interpreter, locationRange LocationRange, key Value, value Value) { referencedValue := v.referencedValue(interpreter) if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6146,7 +6146,7 @@ func (v *EphemeralReferenceValue) String() string { func (v *EphemeralReferenceValue) DynamicType(interpreter *Interpreter) DynamicType { referencedValue := v.referencedValue() if referencedValue == nil { - panic(&DereferenceError{}) + panic(DereferenceError{}) } innerType := (*referencedValue).DynamicType(interpreter) @@ -6195,7 +6195,7 @@ func (v *EphemeralReferenceValue) referencedValue() *Value { func (v *EphemeralReferenceValue) GetMember(interpreter *Interpreter, locationRange LocationRange, name string) Value { referencedValue := v.referencedValue() if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6206,7 +6206,7 @@ func (v *EphemeralReferenceValue) GetMember(interpreter *Interpreter, locationRa func (v *EphemeralReferenceValue) SetMember(interpreter *Interpreter, locationRange LocationRange, name string, value Value) { referencedValue := v.referencedValue() if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6217,7 +6217,7 @@ func (v *EphemeralReferenceValue) SetMember(interpreter *Interpreter, locationRa func (v *EphemeralReferenceValue) Get(interpreter *Interpreter, locationRange LocationRange, key Value) Value { referencedValue := v.referencedValue() if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } @@ -6229,7 +6229,7 @@ func (v *EphemeralReferenceValue) Get(interpreter *Interpreter, locationRange Lo func (v *EphemeralReferenceValue) Set(interpreter *Interpreter, locationRange LocationRange, key Value, value Value) { referencedValue := v.referencedValue() if referencedValue == nil { - panic(&DereferenceError{ + panic(DereferenceError{ LocationRange: locationRange, }) } diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 3a1439a660..2d56a5fd3b 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -3185,7 +3185,7 @@ func TestRuntimeInvokeStoredInterfaceFunction(t *testing.T) { } else { require.Error(t, err) require.IsType(t, Error{}, err) - assert.IsType(t, &interpreter.ConditionError{}, err.(Error).Err) + assert.IsType(t, interpreter.ConditionError{}, err.(Error).Err) } }) } diff --git a/runtime/tests/interpreter/account_test.go b/runtime/tests/interpreter/account_test.go index 29e9945034..e3c4f18045 100644 --- a/runtime/tests/interpreter/account_test.go +++ b/runtime/tests/interpreter/account_test.go @@ -174,7 +174,7 @@ func TestInterpretAuthAccount_save(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.OverwriteError{}, err) + require.IsType(t, interpreter.OverwriteError{}, err) }) }) @@ -206,7 +206,7 @@ func TestInterpretAuthAccount_save(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } @@ -256,7 +256,7 @@ func TestInterpretAuthAccount_save(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.OverwriteError{}, err) + require.IsType(t, interpreter.OverwriteError{}, err) }) }) @@ -288,7 +288,7 @@ func TestInterpretAuthAccount_save(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } @@ -405,7 +405,7 @@ func TestInterpretAuthAccount_load(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -516,7 +516,7 @@ func TestInterpretAuthAccount_load(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -636,7 +636,7 @@ func TestInterpretAuthAccount_copy(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } @@ -772,7 +772,7 @@ func TestInterpretAuthAccount_borrow(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -903,7 +903,7 @@ func TestInterpretAuthAccount_borrow(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -1069,7 +1069,7 @@ func TestInterpretAuthAccount_link(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -1230,7 +1230,7 @@ func TestInterpretAuthAccount_link(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) } }) @@ -1319,7 +1319,7 @@ func TestInterpretAuthAccount_unlink(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) }) @@ -1401,7 +1401,7 @@ func TestInterpretAuthAccount_unlink(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) }) } @@ -1502,7 +1502,7 @@ func TestInterpretAccount_getLinkTarget(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) }) @@ -1594,7 +1594,7 @@ func TestInterpretAccount_getLinkTarget(t *testing.T) { require.Error(t, err) - require.IsType(t, &interpreter.InvalidPathDomainError{}, err) + require.IsType(t, interpreter.InvalidPathDomainError{}, err) }) }) }) diff --git a/runtime/tests/interpreter/capability_test.go b/runtime/tests/interpreter/capability_test.go index 287987f6fe..a7a3d18080 100644 --- a/runtime/tests/interpreter/capability_test.go +++ b/runtime/tests/interpreter/capability_test.go @@ -156,7 +156,7 @@ func TestInterpretCapability_borrow(t *testing.T) { _, err := inter.Invoke("nonExistent") require.Error(t, err) - require.IsType(t, &interpreter.ForceNilError{}, err) + require.IsType(t, interpreter.ForceNilError{}, err) }) t.Run("loop", func(t *testing.T) { @@ -164,7 +164,7 @@ func TestInterpretCapability_borrow(t *testing.T) { _, err := inter.Invoke("loop") require.Error(t, err) - require.IsType(t, &interpreter.CyclicLinkError{}, err) + require.IsType(t, interpreter.CyclicLinkError{}, err) require.Equal(t, err.Error(), @@ -307,7 +307,7 @@ func TestInterpretCapability_borrow(t *testing.T) { _, err := inter.Invoke("nonExistent") require.Error(t, err) - require.IsType(t, &interpreter.ForceNilError{}, err) + require.IsType(t, interpreter.ForceNilError{}, err) }) t.Run("loop", func(t *testing.T) { @@ -315,7 +315,7 @@ func TestInterpretCapability_borrow(t *testing.T) { _, err := inter.Invoke("loop") require.Error(t, err) - require.IsType(t, &interpreter.CyclicLinkError{}, err) + require.IsType(t, interpreter.CyclicLinkError{}, err) require.Equal(t, err.Error(), @@ -471,7 +471,7 @@ func TestInterpretCapability_check(t *testing.T) { _, err := inter.Invoke("loop") require.Error(t, err) - require.IsType(t, &interpreter.CyclicLinkError{}, err) + require.IsType(t, interpreter.CyclicLinkError{}, err) require.Equal(t, err.Error(), @@ -622,7 +622,7 @@ func TestInterpretCapability_check(t *testing.T) { _, err := inter.Invoke("loop") require.Error(t, err) - require.IsType(t, &interpreter.CyclicLinkError{}, err) + require.IsType(t, interpreter.CyclicLinkError{}, err) require.Equal(t, err.Error(), diff --git a/runtime/tests/interpreter/dynamic_casting_test.go b/runtime/tests/interpreter/dynamic_casting_test.go index 585c266042..04ecc9f189 100644 --- a/runtime/tests/interpreter/dynamic_casting_test.go +++ b/runtime/tests/interpreter/dynamic_casting_test.go @@ -159,7 +159,7 @@ func TestInterpretDynamicCastingNumber(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -252,7 +252,7 @@ func TestInterpretDynamicCastingVoid(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -340,7 +340,7 @@ func TestInterpretDynamicCastingString(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -428,7 +428,7 @@ func TestInterpretDynamicCastingBool(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -521,7 +521,7 @@ func TestInterpretDynamicCastingAddress(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -611,7 +611,7 @@ func TestInterpretDynamicCastingStruct(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -653,7 +653,7 @@ func TestInterpretDynamicCastingStruct(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -765,7 +765,7 @@ func testResourceCastInvalid(t *testing.T, types, fromType, targetType string, o require.Error(t, err) require.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) @@ -917,7 +917,7 @@ func testStructCastInvalid(t *testing.T, types, fromType, targetType string, ope require.Error(t, err) require.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) @@ -1122,7 +1122,7 @@ func TestInterpretDynamicCastingSome(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -1214,7 +1214,7 @@ func TestInterpretDynamicCastingArray(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -1313,7 +1313,7 @@ func TestInterpretDynamicCastingDictionary(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } @@ -2225,7 +2225,7 @@ func testReferenceCastInvalid(t *testing.T, types, fromType, targetType string, require.Error(t, err) require.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) @@ -3473,7 +3473,7 @@ func TestInterpretDynamicCastingCapability(t *testing.T) { ) } else { assert.IsType(t, - &interpreter.TypeMismatchError{}, + interpreter.TypeMismatchError{}, err, ) } diff --git a/runtime/tests/interpreter/interpreter_test.go b/runtime/tests/interpreter/interpreter_test.go index 90dad72d23..1708f357d0 100644 --- a/runtime/tests/interpreter/interpreter_test.go +++ b/runtime/tests/interpreter/interpreter_test.go @@ -210,7 +210,7 @@ func TestInterpretInvalidUnknownDeclarationInvocation(t *testing.T) { inter := parseCheckAndInterpret(t, ``) _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.NotDeclaredError{}, err) + assert.IsType(t, interpreter.NotDeclaredError{}, err) } func TestInterpretInvalidNonFunctionDeclarationInvocation(t *testing.T) { @@ -222,7 +222,7 @@ func TestInterpretInvalidNonFunctionDeclarationInvocation(t *testing.T) { `) _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.NotInvokableError{}, err) + assert.IsType(t, interpreter.NotInvokableError{}, err) } func TestInterpretLexicalScope(t *testing.T) { @@ -1972,7 +1972,7 @@ func TestInterpretFunctionPreCondition(t *testing.T) { "test", interpreter.NewIntValueFromInt64(42), ) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) zero := interpreter.NewIntValueFromInt64(0) value, err := inter.Invoke("test", zero) @@ -1999,7 +1999,7 @@ func TestInterpretFunctionPostCondition(t *testing.T) { "test", interpreter.NewIntValueFromInt64(42), ) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) zero := interpreter.NewIntValueFromInt64(0) value, err := inter.Invoke("test", zero) @@ -2025,7 +2025,7 @@ func TestInterpretFunctionWithResultAndPostConditionWithResult(t *testing.T) { "test", interpreter.NewIntValueFromInt64(42), ) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) zero := interpreter.NewIntValueFromInt64(0) value, err := inter.Invoke("test", zero) @@ -2103,11 +2103,11 @@ func TestInterpretFunctionPostConditionWithBeforeFailingPreCondition(t *testing. _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, ast.ConditionKindPre, - err.(*interpreter.ConditionError).ConditionKind, + err.(interpreter.ConditionError).ConditionKind, ) } @@ -2131,11 +2131,11 @@ func TestInterpretFunctionPostConditionWithBeforeFailingPostCondition(t *testing _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, ast.ConditionKindPost, - err.(*interpreter.ConditionError).ConditionKind, + err.(interpreter.ConditionError).ConditionKind, ) } @@ -2157,11 +2157,11 @@ func TestInterpretFunctionPostConditionWithMessageUsingStringLiteral(t *testing. "test", interpreter.NewIntValueFromInt64(42), ) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, "y should be zero", - err.(*interpreter.ConditionError).Message, + err.(interpreter.ConditionError).Message, ) zero := interpreter.NewIntValueFromInt64(0) @@ -2189,11 +2189,11 @@ func TestInterpretFunctionPostConditionWithMessageUsingResult(t *testing.T) { "test", interpreter.NewIntValueFromInt64(42), ) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, "return value", - err.(*interpreter.ConditionError).Message, + err.(interpreter.ConditionError).Message, ) zero := interpreter.NewIntValueFromInt64(0) @@ -2220,11 +2220,11 @@ func TestInterpretFunctionPostConditionWithMessageUsingBefore(t *testing.T) { `) _, err := inter.Invoke("test", interpreter.NewStringValue("parameter value")) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, "parameter value", - err.(*interpreter.ConditionError).Message, + err.(interpreter.ConditionError).Message, ) } @@ -2242,11 +2242,11 @@ func TestInterpretFunctionPostConditionWithMessageUsingParameter(t *testing.T) { `) _, err := inter.Invoke("test", interpreter.NewStringValue("parameter value")) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) assert.Equal(t, "parameter value", - err.(*interpreter.ConditionError).Message, + err.(interpreter.ConditionError).Message, ) } @@ -3826,7 +3826,7 @@ func TestInterpretInterfaceFunctionUseWithPreCondition(t *testing.T) { ) _, err := inter.Invoke("callTest", interpreter.NewIntValueFromInt64(0)) - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) value, err := inter.Invoke("callTest", interpreter.NewIntValueFromInt64(1)) require.NoError(t, err) @@ -3838,7 +3838,7 @@ func TestInterpretInterfaceFunctionUseWithPreCondition(t *testing.T) { _, err = inter.Invoke("callTest", interpreter.NewIntValueFromInt64(2)) assert.IsType(t, - &interpreter.ConditionError{}, + interpreter.ConditionError{}, err, ) }) @@ -3850,9 +3850,9 @@ func TestInterpretInitializerWithInterfacePreCondition(t *testing.T) { t.Parallel() tests := map[int64]error{ - 0: &interpreter.ConditionError{}, + 0: interpreter.ConditionError{}, 1: nil, - 2: &interpreter.ConditionError{}, + 2: interpreter.ConditionError{}, } for _, compositeKind := range common.CompositeKindsWithBody { @@ -4014,23 +4014,23 @@ func TestInterpretTypeRequirementWithPreCondition(t *testing.T) { t.Run("-1", func(t *testing.T) { _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(-1)) require.IsType(t, - &interpreter.ConditionError{}, + interpreter.ConditionError{}, err, ) // NOTE: The type requirement condition (`Test.Nested`) is evaluated first, // before the type's conformances (`Also`) - assert.Equal(t, err.(*interpreter.ConditionError).Message, "x >= 1") + assert.Equal(t, err.(interpreter.ConditionError).Message, "x >= 1") }) t.Run("0", func(t *testing.T) { _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(0)) assert.IsType(t, - &interpreter.ConditionError{}, + interpreter.ConditionError{}, err, ) - assert.Equal(t, "x >= 1", err.(*interpreter.ConditionError).Message) + assert.Equal(t, "x >= 1", err.(interpreter.ConditionError).Message) }) t.Run("1", func(t *testing.T) { @@ -4046,7 +4046,7 @@ func TestInterpretTypeRequirementWithPreCondition(t *testing.T) { t.Run("2", func(t *testing.T) { _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(2)) assert.IsType(t, - &interpreter.ConditionError{}, + interpreter.ConditionError{}, err, ) }) @@ -5805,7 +5805,7 @@ func TestInterpretResourceDestroyExpressionResourceInterfaceCondition(t *testing `) _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) } // TestInterpretInterfaceInitializer tests that the interface's initializer @@ -5832,7 +5832,7 @@ func TestInterpretInterfaceInitializer(t *testing.T) { `) _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) } func TestInterpretEmitEvent(t *testing.T) { @@ -6314,7 +6314,7 @@ func TestInterpretReferenceDereferenceFailure(t *testing.T) { `) _, err := inter.Invoke("test") - assert.IsType(t, &interpreter.DestroyedCompositeError{}, err) + assert.IsType(t, interpreter.DestroyedCompositeError{}, err) } func TestInterpretInvalidForwardReferenceCall(t *testing.T) { @@ -6942,7 +6942,7 @@ func TestInterpretConformToImportedInterface(t *testing.T) { require.NoError(t, err) _, err = inter.Invoke("test") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) } func TestInterpretFunctionPostConditionInInterface(t *testing.T) { @@ -6997,7 +6997,7 @@ func TestInterpretFunctionPostConditionInInterface(t *testing.T) { require.NoError(t, err) _, err = inter.Invoke("test2") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) } func TestInterpretFunctionPostConditionWithBeforeInInterface(t *testing.T) { @@ -7052,7 +7052,7 @@ func TestInterpretFunctionPostConditionWithBeforeInInterface(t *testing.T) { require.NoError(t, err) _, err = inter.Invoke("test2") - assert.IsType(t, &interpreter.ConditionError{}, err) + assert.IsType(t, interpreter.ConditionError{}, err) } func TestInterpretContractUseInNestedDeclaration(t *testing.T) { @@ -7132,8 +7132,8 @@ func TestInterpretResourceInterfaceInitializerAndDestructorPreConditions(t *test _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(1)) require.Error(t, err) - require.IsType(t, &interpreter.ConditionError{}, err) - assert.Equal(t, "invalid init", err.(*interpreter.ConditionError).Message) + require.IsType(t, interpreter.ConditionError{}, err) + assert.Equal(t, "invalid init", err.(interpreter.ConditionError).Message) }) t.Run("2", func(t *testing.T) { @@ -7145,8 +7145,8 @@ func TestInterpretResourceInterfaceInitializerAndDestructorPreConditions(t *test _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(3)) require.Error(t, err) - require.IsType(t, &interpreter.ConditionError{}, err) - assert.Equal(t, "invalid destroy", err.(*interpreter.ConditionError).Message) + require.IsType(t, interpreter.ConditionError{}, err) + assert.Equal(t, "invalid destroy", err.(interpreter.ConditionError).Message) }) } @@ -7204,8 +7204,8 @@ func TestInterpretResourceTypeRequirementInitializerAndDestructorPreConditions(t _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(1)) require.Error(t, err) - require.IsType(t, &interpreter.ConditionError{}, err) - assert.Equal(t, "invalid init", err.(*interpreter.ConditionError).Message) + require.IsType(t, interpreter.ConditionError{}, err) + assert.Equal(t, "invalid init", err.(interpreter.ConditionError).Message) }) t.Run("2", func(t *testing.T) { @@ -7217,8 +7217,8 @@ func TestInterpretResourceTypeRequirementInitializerAndDestructorPreConditions(t _, err := inter.Invoke("test", interpreter.NewIntValueFromInt64(3)) require.Error(t, err) - require.IsType(t, &interpreter.ConditionError{}, err) - assert.Equal(t, "invalid destroy", err.(*interpreter.ConditionError).Message) + require.IsType(t, interpreter.ConditionError{}, err) + assert.Equal(t, "invalid destroy", err.(interpreter.ConditionError).Message) }) } @@ -7288,7 +7288,7 @@ func TestInterpretNonStorageReferenceAfterDestruction(t *testing.T) { _, err := inter.Invoke("test") require.Error(t, err) - assert.IsType(t, &interpreter.DestroyedCompositeError{}, err) + assert.IsType(t, interpreter.DestroyedCompositeError{}, err) } func TestInterpretNonStorageReferenceToOptional(t *testing.T) { @@ -7335,7 +7335,7 @@ func TestInterpretNonStorageReferenceToOptional(t *testing.T) { _, err := inter.Invoke("testNil") require.Error(t, err) - assert.IsType(t, &interpreter.DereferenceError{}, err) + assert.IsType(t, interpreter.DereferenceError{}, err) }) } @@ -7665,7 +7665,7 @@ func TestInterpretResourceAssignmentForceTransfer(t *testing.T) { _, err := inter.Invoke("test") require.Error(t, err) - assert.IsType(t, &interpreter.ForceAssignmentToNonNilResourceError{}, err) + assert.IsType(t, interpreter.ForceAssignmentToNonNilResourceError{}, err) }) t.Run("existing to nil", func(t *testing.T) { @@ -7701,7 +7701,7 @@ func TestInterpretResourceAssignmentForceTransfer(t *testing.T) { _, err := inter.Invoke("test") require.Error(t, err) - assert.IsType(t, &interpreter.ForceAssignmentToNonNilResourceError{}, err) + assert.IsType(t, interpreter.ForceAssignmentToNonNilResourceError{}, err) }) } @@ -7742,7 +7742,7 @@ func TestInterpretForce(t *testing.T) { _, err := inter.Invoke("test") require.Error(t, err) - assert.IsType(t, &interpreter.ForceNilError{}, err) + assert.IsType(t, interpreter.ForceNilError{}, err) }) } diff --git a/runtime/tests/interpreter/transactions_test.go b/runtime/tests/interpreter/transactions_test.go index 5aada94e14..2a259f728e 100644 --- a/runtime/tests/interpreter/transactions_test.go +++ b/runtime/tests/interpreter/transactions_test.go @@ -104,9 +104,9 @@ func TestInterpretTransactions(t *testing.T) { `) err := inter.InvokeTransaction(0) - require.IsType(t, &interpreter.ConditionError{}, err) + require.IsType(t, interpreter.ConditionError{}, err) - conditionErr := err.(*interpreter.ConditionError) + conditionErr := err.(interpreter.ConditionError) assert.Equal(t, conditionErr.ConditionKind, ast.ConditionKindPre) }) @@ -156,9 +156,9 @@ func TestInterpretTransactions(t *testing.T) { `) err := inter.InvokeTransaction(0) - require.IsType(t, &interpreter.ConditionError{}, err) + require.IsType(t, interpreter.ConditionError{}, err) - conditionErr := err.(*interpreter.ConditionError) + conditionErr := err.(interpreter.ConditionError) assert.Equal(t, conditionErr.ConditionKind, ast.ConditionKindPost) }) @@ -188,7 +188,7 @@ func TestInterpretTransactions(t *testing.T) { // third transaction is not declared err = inter.InvokeTransaction(2) - assert.IsType(t, &interpreter.TransactionNotDeclaredError{}, err) + assert.IsType(t, interpreter.TransactionNotDeclaredError{}, err) }) t.Run("TooFewArguments", func(t *testing.T) { @@ -199,7 +199,7 @@ func TestInterpretTransactions(t *testing.T) { `) err := inter.InvokeTransaction(0) - assert.IsType(t, &interpreter.ArgumentCountError{}, err) + assert.IsType(t, interpreter.ArgumentCountError{}, err) }) panicFunction := interpreter.NewHostFunctionValue(func(invocation interpreter.Invocation) trampoline.Trampoline { @@ -236,11 +236,11 @@ func TestInterpretTransactions(t *testing.T) { // first transaction err := inter.InvokeTransaction(0, signer1) - assert.IsType(t, &interpreter.ArgumentCountError{}, err) + assert.IsType(t, interpreter.ArgumentCountError{}, err) // second transaction err = inter.InvokeTransaction(0, signer1, signer2) - assert.IsType(t, &interpreter.ArgumentCountError{}, err) + assert.IsType(t, interpreter.ArgumentCountError{}, err) }) t.Run("Parameters", func(t *testing.T) {