Skip to main content

W0049 - Prefer [{version, 2}] when constructing a set

Error

-module(main).
foo() -> sets:new().
%% ^^^^^^^^^^ 💡 warning: Prefer `[{version, 2}]` when constructing a set.

Explanation

Erlang/OTP 24.0 introduced a new internal representation for sets which is more performant. Developers can use this new representation by passing the {version, 2} flag to new/1 and from_list/2, such as sets:new([{version, 2}]). This new representation will become the default in future Erlang/OTP versions. Functions that work on two sets, such as union/2 and similar, will work with sets of different versions. In such cases, there is no guarantee about the version of the returned set. Explicit conversion from the old version to the new one can be done with sets:from_list(sets:to_list(Old), [{version,2}]).

For more information, see https://www.erlang.org/doc/man/sets.html