Skip to content

Commit

Permalink
Revert switch to catch since it was breaking stuff. Add tests for thi…
Browse files Browse the repository at this point in the history
…s case.
  • Loading branch information
radeusgd committed Jan 24, 2022
1 parent 39adfee commit a682817
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ type Vector
at : Integer -> Any ! Index_Out_Of_Bounds_Error
at index =
actual_index = if index < 0 then this.length + index else index
case actual_index of
_ ->
Panic.recover (this.to_array.at actual_index) . catch err-> case err of
Invalid_Array_Index_Error _ _ -> Error.throw (Index_Out_Of_Bounds_Error index this.length)
_ -> Panic.throw err
if actual_index>=0 && actual_index<this.length then this.unsafe_at actual_index else
Error.throw (Index_Out_Of_Bounds_Error index this.length)

## ADVANCED
UNSTABLE
Expand Down
5 changes: 5 additions & 0 deletions test/Tests/src/Data/Vector_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ spec = Test.group "Vectors" <|
[1,2,3].at 0 . should_equal 1
[1,2,3].at 2 . should_equal 3

Test.specify "should allow to store dataflow errors and raise them on access" <|
vec = [Error.throw (My_Error "foo"), "bar"]
vec.at 1 . should_equal "bar"
vec.at 0 . should_fail_with My_Error

Test.specify "should allow accessing elements with negative indices" <|
[1,2,3].at -1 . should_equal 3
[1,2,3].at -2 . should_equal 2
Expand Down

0 comments on commit a682817

Please sign in to comment.