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:
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:
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:
const a = 1;
var s = <int>{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.
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.