Open
Description
A note for the community
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Problem
The built-in functions to coerce values can be both fallible and not fallible depending on the value.
The functions are documented as fallible but if the compiler can detect that the value is of a certain type, it changes the signature from fallible to not fallible.
For example, this is a valid syntax and compiles:
str = "something"
result, err = to_bool(str)
But this fails:
b = false
result, err = to_bool(b)
with
error[E104]: unnecessary error assignment
┌─ :1:9
│
1 │ result, err = to_bool(b)
│ ------ ^^^ ---------- because this expression can't fail
│ │ │
│ │ this error assignment is unnecessary
│ use: result = to_bool(b)
The same occurs with to_float()
, to_int()
, ...
The signature changes from:
to_bool(value: <boolean | integer | float | null | string>)
:: <boolean> , <error>
to:
to_bool(value: <boolean>) :: <boolean> // not fallible
As a language user this can be confusing, a function should not change fallibility depending on the parameter value.
Configuration
No response
Version
0.27
Debug Output
No response
Example Data
No response
Additional Context
No response
References
No response