-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Description
Many uses of List.from can be changed to List.of.
The reasons to do so:
List.ofis nicer to use because the extra constraint helps type inference and editor suggestionsList.ofis more efficient- There is an education problem that since
List.ofis newer, there are lots of poor examples ofList.fromthat could have been migrated toList.of.
Examples that could be hints (i.e. no false positives):
- The explicit or inferred type argument
EinList<E>.from(iterable)matches the static type of the iterable argument - The explicit type argument
EinList<E>.from(iterable)is a supertype of the static type of the iterable argument
More complicated is where dynamic creeps in.
I have seen examples like:
void foo(Map<String, String> map) {
for (final key in List.from(map.keys)) {
print(key.isEmpty);
...If we change List.from to List.of, the inferred type of key moves from dynamic to String. This would be helpful to the developer for completion suggestion, since key.isE• can now only complete to key.isEmpty, and not key.isEven.
We would want to suggest the replacement if the new inferred types do not lead to new or different errors or warnings or a different resolution of elements (e.g. a dynamic instance method call becoming a static extension method call).
srawlins, parlough, pq, PiN73, dnfield and 10 moreLevi-Lesches
Metadata
Metadata
Assignees
Labels
P3A lower priority bug or feature requestA lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug