duplicate_rest_element_in_pattern
At most one rest element is allowed in a list or map pattern.
Description
#The analyzer produces this diagnostic when there's more than one rest pattern in either a list or map pattern. A rest pattern will capture any values unmatched by other subpatterns, making subsequent rest patterns unnecessary because there's nothing left to capture.
Example
#The following code produces this diagnostic because there are two rest patterns in the list pattern:
dart
void f(List<int> x) {
if (x case [0, ..., ...]) {}
}
Common fixes
#Remove all but one of the rest patterns:
dart
void f(List<int> x) {
if (x case [0, ...]) {}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.