-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add support for failable mark to function declarations #300
Conversation
244345c
to
eea62eb
Compare
Right now there are two versions:
Which route should be taken here? If we allow declaring non-failable functions to be failable, then should a warning be emmited? If so, should there be a compiler flag to remove it? |
Allowing to mark non-failable functions can be seen as a feature to allow API stability. However, this obviously allows for misuse — having too many pseudo-failable functions in libraries would make it more annoying to use them. Maybe for now it is a good idea to stick to the more strict but minimal rule of "only failable functions must be marked". Then, it would be possible to relax it, if ever needed. |
The difference with unsafe is...? In this way when we will improve docs we can explain it. |
...that they are completely different things
it will help for user to know if the function is failable or not, and probably open up a possibility for handling a runtime error in the function (like |
To clarify, this change does not add any new features. It only creates a requirement to mark failable functions with the Well, the last commit does add a new feature of marking any function with the |
@mks-h so it kinda just ignores the |
In the first case, it throws an error if there's a P.S. Technically it changes the "failable" property to true, instead of just ignoring the mark. |
ah, so it would just pass an error along if there is a |
I'm not sure what you are asking. Can you elaborate? As a general answer — the way you use failable functions doesn't change. Whatever is considered a failable function now, also doesn't change. In the first variant, the one I prefer, the only thing that changes — is that if a function is already failable (per whatever definition of a failable function there is), you are also required to put the In the second variant, the last rule about forbidding to use the |
@mks-h Let’s implement the strict version now which disallows the scenario to mark an infailable function a failable.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some required changes
You need to align with the latest changes. |
Re-implemented the PR to have a |
The latest changes remove the ability to write |
@mks-h You can add the error tests to a separate rust file If you move the tests - I will approve and we will merge this request |
Thanks to new tests, I've discovered bugs related to making Failable a data type. I've managed to fix them in one sweep by writing custom PartialEq implementation for |
In the meantime I approved for the CI so we can see if it pass or not :-) Edit: Pass |
So with a |
Oops, I forgot to actually enable the error tests. But by the "new tests" I meant that some tests have been added to the IIRC, one issue was that the actual return type was a non-failable variant, while the declared return type was a corresponding Failable type — so they were different, and therefore the test didn't succeed. Another issue was similar in nature, but with the As a quick fix I've implemented manual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one relatively small change
And we get back that |
Updated to properly handle casts. The next thing to do, is to make handlers of failable things ( |
I changed this pr to draft as you said that is missing some stuff so we are sure that do't get merged if not ready :-) Thanks for your work! |
3150c11
to
dcc7499
Compare
I'm fairly confident this is it:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job @mks-h 👏👏👏 solid work. Thank you for your contribution
* test: Add tests for functions with return types * feat: Introduce Failable type * feat: Require only failable functions to always return Failable type * fix: Disallow declaring Failable types in function arguments * fix: Make return statement accept non-Failable versions of type * fix: Make it absurd to cast Failable and non-Failable types * fix: Unwrap Failable type by handling failure * fix: Make commands always return failable "Text?"
Makes it a requirement to declare failable functions as such, using
?
failable mark.Syntax:
Resolves #272