diff --git a/runtime/tests/interpreter/dynamic_casting_test.go b/runtime/tests/interpreter/dynamic_casting_test.go index b3d90899f5..6113f960f6 100644 --- a/runtime/tests/interpreter/dynamic_casting_test.go +++ b/runtime/tests/interpreter/dynamic_casting_test.go @@ -3899,6 +3899,7 @@ func TestInterpretDynamicCastingReferenceCasting(t *testing.T) { type testCase struct { operation ast.Operation returnsOptional bool + checkError func(t *testing.T, err error) } test := func(testCase testCase) { @@ -3952,12 +3953,7 @@ func TestInterpretDynamicCastingReferenceCasting(t *testing.T) { _, err := inter.Invoke("test") RequireError(t, err) - // StorageReferenceValue.ReferencedValue turns the ForceCastTypeMismatchError - // of the failed dereference into a DereferenceError - var dereferenceError interpreter.DereferenceError - require.ErrorAs(t, err, &dereferenceError) - - assert.Equal(t, 22, dereferenceError.LocationRange.StartPosition().Line) + testCase.checkError(t, err) }) } @@ -3965,10 +3961,22 @@ func TestInterpretDynamicCastingReferenceCasting(t *testing.T) { { operation: ast.OperationForceCast, returnsOptional: false, + checkError: func(t *testing.T, err error) { + // StorageReferenceValue.ReferencedValue turns the ForceCastTypeMismatchError + // of the failed dereference into a DereferenceError + var dereferenceError interpreter.DereferenceError + require.ErrorAs(t, err, &dereferenceError) + + assert.Equal(t, 22, dereferenceError.LocationRange.StartPosition().Line) + }, }, { operation: ast.OperationFailableCast, returnsOptional: true, + checkError: func(t *testing.T, err error) { + var mismatchError interpreter.ForceCastTypeMismatchError + require.ErrorAs(t, err, &mismatchError) + }, }, }