You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dart allows if (e case p when c) ....
It should also allow while (e case p when c) ....
The true branch is the loop body, which is where the bound values are available.
An example use could be finding the last element of a linked list:
while (cursor.next casevar next?) cursor = next;
Generally if and while are mostly symmetric, and the behavior here can be emulated by:
while (true) {
if (cursor.next casevar next?) cursor = next;
elsebreak;
}
(Even if Dart doesn't make (e case p when c) a general boolean expression, it can still safely and meaningfully be allowed in a few more cases, mainly [conditional expression][#2664] and while conditions. I doesn't make sense for do/while since the true branch isn't dominated by the condition.)
The text was updated successfully, but these errors were encountered:
lrhn
added
feature
Proposed language feature that solves one or more problems
patterns
Issues related to pattern matching.
labels
Jun 20, 2024
The for should work too. It's a little crowded syntactically, and it's not completely clear whether any bound variables are in scope for the increment-expressions or not. Still, the check being true dominates the body and increments, so it should probably just work for those.
Dart allows
if (e case p when c) ...
.It should also allow
while (e case p when c) ...
.The
true
branch is the loop body, which is where the bound values are available.An example use could be finding the last element of a linked list:
Generally
if
andwhile
are mostly symmetric, and the behavior here can be emulated by:(Even if Dart doesn't make
(e case p when c)
a general boolean expression, it can still safely and meaningfully be allowed in a few more cases, mainly [conditional expression][#2664] andwhile
conditions. I doesn't make sense fordo
/while
since the true branch isn't dominated by the condition.)The text was updated successfully, but these errors were encountered: