-
Notifications
You must be signed in to change notification settings - Fork 53
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
checking-keyword expression
as a statement, where x
is not a function-call-expr
or method-call-expr
#588
Comments
That's an interesting example. The spec doesn't allow this currently. We don't want to allow statements to arbitrary expressions, because something like:
makes no sense. Similarly, we don't want to allow We could change checking-action to:
Are there any other kinds of expression that make sense after |
Even though not as appealing as the original example, I would think even an expression like member access may be used with the checking-keyword? import ballerina/log;
map<error> errMap = {};
function getError(string key) returns error {
// If the map has an entry with the specified key, return the value.
check errMap[key];
// If not, add a new error to the map, and return the new error.
log:printInfo(string `Adding a new error entry for key '${key}'`);
error e = error(string `Key '${key}' not found`);
errMap[key] = e;
return e;
} We can of course write the same in different ways; a combination of But, should we consider allowing this with any expression whose static type is a subtype of |
So your idea is:
? That's an interesting idea. I don't understand why you suggest that the constraint should require that it contain a subtype of We should in any case have a constraint on |
The suggestion to require a subtype of nil in this scenario was because if that is not the case, the static type of |
Let me rephrase: why does it make sense to restrict the static type to be a subtype of |
Sorry, that suggestion was specifically for the proposed change to Using |
We currently have in https://ballerina.io/spec/lang/2022R1/#call-stmt
We would then change this to be two statements. First:
with the constraint that the static type of call-expr is nil or never. Second:
with the constraint that the static type of the checking-expr must be nil. @MaryamZi Please review. |
This grammar will get changed by #1059 |
Description:
Can we use
check x;
orcheckpanic x;
as statements, wherex
is not acall-expr
?@pubudu91 pointed out that the spec only allows
checking-keyword
incall-stmt
in statements.IMO, this could be useful.
For example,
If this is not allowed, the user would have to use a type guard to check if
x
is an error and return?The implementation allows this at the moment.
The text was updated successfully, but these errors were encountered: