-
Notifications
You must be signed in to change notification settings - Fork 170
skip nullable iterables in avoid_function_literals_in_foreach_calls
#2752
Conversation
avoid_function_literals_in_foreach_calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM assuming it works with dynamic
.
|
||
bool _isNonNullableIterable(DartType? type) => | ||
type != null && | ||
type.nullabilitySuffix != NullabilitySuffix.question && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how this works for dynamic
. Consider
void f(dynamic iter) => iter?.forEach(...);
Is the suffix always a question even when it isn't explicitly given?
I'll just note that an equivalent test might be to look for the ?.
operator on the method invocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the suffix always a question even when it isn't explicitly given?
I believe so? (@scheglov may knot for sure.)
In any event, I added a dynamic
test case and it seems to work as written.
Thanks for the catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type dynamic
is always nullable, and it does not have any nullabilitySuffix
, it is always NullabilitySuffix.none
. Note that the suffix is not the same as nullability, e.g. FutureOr<int?>
is nullable.
…dart-lang/linter#4330) Fixes dart-lang/linter#4328. Reverts dart-lang/linter#4039 that caused false negatives in non-null-safe mode. And reverts dart-lang/linter#2752 along with it because it was not the exact right fix in the first place. Null-aware calls are since handled by dart-lang/linter#4305 and all the existing tests still pass.
Fixes #dart-lang/sdk#58444
/cc @bwilkerson