-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
Feature request: adding description field to the @return!
contract
#1986
Comments
Can you explain what you want with an example? |
Something along those lines: <*
String checksum
@return! Error.ARGUMENT "Empty string is not allowed"
@return! MathError.ZERO_DIVISION : "Magic number should be non-zero"
// Old behavior should be preserved
@return! Error.ARGUMENT
@return! Error.ARGUMENT, MathError.ZERO_DIVISION
*>
fn int! checksum(String s, int magic) {
if (!s) return Error.ARGUMENT?;
if (magic == 0) MathError.ZERO_DIVISION?;
int sum = 0;
foreach(c : s) sum += c;
return sum / magic;
} And another crazy idea came to my mind. What if we could extract the error message with reflection mechanism from function pointer/signature: int! csum = checksum("foo", 0);
if (catch err = csum) {
io::printfn("Error: %s -- %s", err, checksum.strerror(err));
// Or via some builtin / macro
//io::printfn("Error: %s -- %s", err, @strerror(checksum, err));
}
// Prints
Error: ARGUMENT -- Magic number should be non-zero |
With the functionality above, this could be interlinked with #1985 |
But isn't a description already possible today? |
Indeed it's possible, but it's not in the docs :( |
I added it to the docs now. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should we consider adding optional text description to
@return!
contract with explanations when the error can be returned?The text was updated successfully, but these errors were encountered: