-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
In #7257, which has been accepted, @thejoshwolfe says:
status quo
const one: ?u32 = 1;
const two: ?u32 = 2;
// the second if is an expr hence it requires a ;
if (one) |foo| if (two) |bar| {
// …
};
proposal
const one: ?u32 = 1;
const two: ?u32 = 2;
if (one, two) |foo, bar| {
// …
}
It's pretty much straightforward to me, but Ill add that it is obviously a AND (not a OR) so you will reach the else if at least one of the two is null.
Of course the order will have to be matched for the else captures:
const a: anyerror!u32 = 0;
const b: anyerror!u32 = error.BadValue;
if (a, b) |foo, bar| {
unreachable;
} else |_, err| {
expect(err == error.BadValue);
}
The only downsides that I see is if the if body is huge it will require a back and forth to check the order which can induce errors but on the other hand it will also promote the good practice of refactoring your code into smaller chunks (so that you see both the if and the else).
00JCIV00 and RyanDeivert555Guigui220D, komuw, g-w1 and SuperAuguste
Metadata
Metadata
Assignees
Labels
proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.