duplicate_rest_element_in_pattern
列表或對映模式中最多允許一個 rest 元素。
描述
#當列表或對映模式中存在多個 rest 模式時,分析器會生成此診斷資訊。rest 模式將捕獲任何與其它子模式不匹配的值,這使得後續的 rest 模式變得不必要,因為已經沒有剩餘內容可供捕獲。
示例
#以下程式碼會生成此診斷資訊,因為列表模式中有兩個 rest 模式
dart
void f(List<int> x) {
if (x case [0, ..., ...]) {}
}常見修復方法
#移除除一個之外的所有 rest 模式
dart
void f(List<int> x) {
if (x case [0, ...]) {}
}