equal_elements_in_set
Two elements in a set literal shouldn't be equal.
Description
#The analyzer produces this diagnostic when an element in a non-constant set is the same as a previous element in the same set. If two elements are the same, then the second value is ignored, which makes having both elements pointless and likely signals a bug.
Example
#The following code produces this diagnostic because the element 1
appears
twice:
dart
const a = 1;
const b = 1;
var s = <int>{a, b};
Common fixes
#If both elements should be included in the set, then change one of the elements:
dart
const a = 1;
const b = 2;
var s = <int>{a, b};
If only one of the elements is needed, then remove the one that isn't needed:
dart
const a = 1;
var s = <int>{a};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。