The implicit conditional execution seems non-ideal to me, as it seems like it could be very easily lead to bugs where one forgets to handle an error and important code is just skipped silently. If you want this pattern, (though I'm not sure that it's necessary) then perhaps use ? to indicate you are doing this. (See Swift's optional chaining):
int! foo = something_fallible();
int! bar = takes_an_int(foo?);
Also, if a function returns a void!, then is it allowed to be invoked on a line by itself?
You also, there is an interesting interaction with defer. There are cases where you want defer on normal return, error return, or both. I'm not sure what the best way to write these is. Also, it would be useful to be able to access errors in the error version of defer, for logging, etc. Or even be able to modify the error, for instance to add a stack trace. I'm not sure of the usefulness in the other cases, but they probably exist, and it would probably be good to add for symmetry. Actually, if a single defer gave access to the value, one could check whether it was an error or normal return.
A couple thoughts:
The implicit conditional execution seems non-ideal to me, as it seems like it could be very easily lead to bugs where one forgets to handle an error and important code is just skipped silently. If you want this pattern, (though I'm not sure that it's necessary) then perhaps use
?
to indicate you are doing this. (See Swift's optional chaining):Also, if a function returns a
void!
, then is it allowed to be invoked on a line by itself?You also, there is an interesting interaction with
defer
. There are cases where you wantdefer
on normal return, error return, or both. I'm not sure what the best way to write these is. Also, it would be useful to be able to access errors in the error version of defer, for logging, etc. Or even be able to modify the error, for instance to add a stack trace. I'm not sure of the usefulness in the other cases, but they probably exist, and it would probably be good to add for symmetry. Actually, if a singledefer
gave access to the value, one could check whether it was an error or normal return.There are some possibilities if one wants to guard against forgotten errors - and those are similar to Go:
The above may be set as simply warnings or notices.
And yes, a function returning
void!
can be invoked on a line by itself.defer
,defer catch
anddefer try
will invoke on any, error and normal return respectively.The error is likely to be available in the catch version of the defer.
It is an interesting idea to unify them. I’ll give it some thought.