Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.getUnsafe does not throw Not_found if index doesn't exist in array #172

Open
dsiu opened this issue Dec 30, 2023 · 1 comment
Open

Comments

@dsiu
Copy link

dsiu commented Dec 30, 2023

According to Core__Array.resi, Array.getUnsafe should throw Not_found if the index is out of bounds. However, this is not the case; it returns undefined instead.

ReScript Playground Link

/**
`getUnsafe(array, index)` returns the element at `index` of `array`.
This is _unsafe_, meaning it will fail with an exception if `index` does not exist in `array`.
## Exceptions
- `Not_found`: If the provided `index` does not exist in `array`.
## Examples
```rescript
let array = ["Hello", "Hi", "Good bye"]
Console.log(array->Array.getUnsafe(0)) // "Hello"
Console.log(array->Array.getUnsafe(3)) // Fails and raises exception
```
*/
@raises(Not_found)
external getUnsafe: (array<'a>, int) => 'a = "%array_unsafe_get"

@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Array.getUnsafe doesn't throw Not_found if index doesn't exist in *array* Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in *array* Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe doesn't throw Not_found if index doesn't exist in array Array.getUnsafe does not throw Not_found if index doesn't exist in array Dec 30, 2023
@dsiu dsiu changed the title Array.getUnsafe does not throw Not_found if index doesn't exist in array Array.getUnsafe does not throw Not_found if index doesn't exist in array Dec 30, 2023
dsiu added a commit to dsiu/rescript-stdlib-fp that referenced this issue Dec 30, 2023
…'s `getExn` for `getUnsafe` instead of RescriptCore since there is a bug in RescriptCore's `getUnsafe` not raising `Not_Found` (see: rescript-association/rescript-core#172)
@DZakh
Copy link
Contributor

DZakh commented Dec 31, 2023

Fixed by #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants