rest_element_in_map_pattern
Map 模式不能包含 rest 模式。
描述
#当 map 模式包含 rest 模式时,分析器会产生此诊断。Map 模式匹配的 map 可以包含比模式中显式指定的键更多的键(只要指定的键匹配),因此 rest 模式是不必要的。
示例
#以下代码产生此诊断,因为 map 模式包含 rest 模式
dart
void f(Map<int, String> x) {
if (x case {0: _, ...}) {}
}
常见修复
#移除 rest 模式
dart
void f(Map<int, String> x) {
if (x case {0: _}) {}
}