[erlang-questions] Unions of Cardinality > 13

AJ Foster web@REDACTED
Mon Feb 19 06:27:20 CET 2018


Hello,

I am new to the Erlang ecosystem, so please excuse / assist with my vocabulary. I’ve observed that Dialyzer behaves differently with union types of different cardinality, with a threshold of 13 items. An example is below:

    -module(atom_widening).
    -export([example1/1, example2/1, main/0]).

    % Cardinality above 13 -> not checked as expected.
    -type value1() :: 1..14.

    -spec example1(value1()) -> ok | error.
    example1(A) when A >= 1, A =< 10 -> ok;
    example1(_) -> error.

    % Cardinality not above 13 -> checked as expected.
    -type value2() :: 1..13.

    -spec example2(value2()) -> ok | error.
    example2(A) when A >= 1, A =< 10 -> ok;
    example2(_) -> error.

    main() ->
      error = example1(15), % Passes successfully.
      error = example2(15). % Warning: breaks the contract.


Similar behavior occurs with unions of atoms; unions of up to 13 atoms are checked as I expect, but unions of 14 or more atoms are not. This behavior appears to be intentional according to this: https://github.com/erlang/otp/blob/master/lib/dialyzer/test/small_SUITE_data/src/atom_widen.erl <https://github.com/erlang/otp/blob/master/lib/dialyzer/test/small_SUITE_data/src/atom_widen.erl>

My questions: where is this threshold defined, and can it be configured? Alternatively, is there a better way of constructing large union types that will allow Dialyzer to check them as “strictly” as types with fewer items?

Thank you for your time,
- AJ

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180219/6ac83454/attachment.htm>


More information about the erlang-questions mailing list