-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Hint and/or lint for changing List/Set/Map from to of #58359
Copy link
Copy link
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
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
Many uses of
List.fromcan be changed toList.of.The reasons to do so:
List.ofis nicer to use because the extra constraint helps type inference and editor suggestionsList.ofis more efficientList.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):
EinList<E>.from(iterable)matches the static type of the iterable argumentEinList<E>.from(iterable)is a supertype of the static type of the iterable argumentMore complicated is where
dynamiccreeps in.I have seen examples like:
If we change
List.fromtoList.of, the inferred type ofkeymoves fromdynamictoString. This would be helpful to the developer for completion suggestion, sincekey.isE•can now only complete tokey.isEmpty, and notkey.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).