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

Add support for failable mark to function declarations #300

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mks-h
Copy link

@mks-h mks-h commented Jul 12, 2024

Makes it a requirement to declare failable functions as such, using ? failable mark.

Syntax:

fun test(): Null ? {
    fail 1
}

Resolves #272

Failable functions which specify return type must be marked
with a question mark after the type, with a space in-between.
Example:

fun failable(): Null ? { fail 1 }

Non-failable functions must not be marked as failable.
Allow marking non-failable functions as failable.
@mks-h
Copy link
Author

mks-h commented Jul 13, 2024

Right now there are two versions:

  1. On commit 13f278c it is required to mark failable functions, and forbidden to mark non-failable functions.
  2. On commit eea62eb non-failable functions will be considered failable, if marked.

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?

@mks-h mks-h marked this pull request as ready for review July 13, 2024 00:15
@mks-h
Copy link
Author

mks-h commented Jul 13, 2024

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.

@Mte90
Copy link
Member

Mte90 commented Jul 13, 2024

The difference with unsafe is...?

In this way when we will improve docs we can explain it.

@b1ek
Copy link
Member

b1ek commented Jul 13, 2024

The difference with unsafe is...

...that they are completely different things

unsafe marks a command execution statement as failable, while this marks a function failable in the function declaration.

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 $...$ failed {})

@mks-h
Copy link
Author

mks-h commented Jul 13, 2024

To clarify, this change does not add any new features. It only creates a requirement to mark failable functions with the ? in their signatures. This is purely for readability purposes, so that it is easy to differentiate these functions without looking into their bodies, or waiting for compiler to yell at you for missing the failable block.

Well, the last commit does add a new feature of marking any function with the ? to make them failable, but I'd rather not merge it, at least not yet.

@b1ek
Copy link
Member

b1ek commented Jul 13, 2024

@mks-h so it kinda just ignores the ? symbol in there so it wont throw a syntax error?

@mks-h
Copy link
Author

mks-h commented Jul 13, 2024

In the first case, it throws an error if there's a ? mark on a non-failable function, or no ? on a failable one. In the second case, if there's a ? on a non-failable function, instead of erroring out, it turns the function into a failable one — so you have to call it like one.

P.S. Technically it changes the "failable" property to true, instead of just ignoring the mark.

@b1ek
Copy link
Member

b1ek commented Jul 14, 2024

ah, so it would just pass an error along if there is a $...$? block inside the function

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

Successfully merging this pull request may close these issues.

[Feature] Explicitly mark failable functions in their signatures
3 participants