Closed
Description
It is frequently more readable to give a boolean expression a name for self-documentation. For example:
final bool isSingleElement = fields == null;
if (!isSingleElement) {
fields.forEach(...);
}
However, this does not promote fields
to non-null inside the if
block. A workaround is to remove the variable:
if (fields != null) {
fields.forEach(...);
}
However, this makes the code less readable, because non-nullness of fields
does not immediately imply that we're dealing with a "single line" mode of something.
Can the nullability inference be enhanced to infer using local booleans?