language icon indicating copy to clipboard operation
language copied to clipboard

yield if not null

Open jscholler opened this issue 1 month ago • 2 comments

This is not a new idea (https://github.com/dart-lang/language/issues/2307). But in the light of the latest feature with the "?" prefix:

{ 'name': ?hello }
[ ?hello ]

Why:

yield ?hello;

Or even:

return ?hello;

Does not exist?

jscholler avatar Oct 31 '25 19:10 jscholler

yield ?expr; could make sense. It's an operation that can be omitted, so doing nothing if the value is null is valid.

return ?expr; probably won't work. If it just returns without a value if expr is null, that's exactly the same as return expr;. If it doesn't return at all, that'll be very confusion.

There are several places where "do nothing if the value is null" makes sense. It would be nice to have a coherent feature, rather than adding each of these piecemeal.

lrhn avatar Oct 31 '25 19:10 lrhn

I searched on GitHub (the results are very limited) and found a few places where yield ?expr; can fit: util.dart#L43, ast.dart#L28 and core.dart#L48.

Wdestroier avatar Nov 04 '25 00:11 Wdestroier