DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1328

Two elements in a constant set literal can't be equalDRT-W1328

Major severityMajor
Bug Risk categoryBug Risk

The analyzer produces this diagnostic when two elements in a constant set literal have the same value. The set can only contain each value once, which means that one of the values is unnecessary.

Example

The following code produces this diagnostic because the string 'a' is specified twice:

const Set<String> set = {'a', 'a'};

Common fixes

Remove one of the duplicate values:

const Set<String> set = {'a'};

Note that literal sets preserve the order of their elements, so the choice of which element to remove might affect the order in which elements are returned by an iterator.