[erlang-questions] Dialyzer

Fred Hebert <>
Sun Jan 20 17:34:01 CET 2019


On 01/20, Frans Schneider wrote:
>Dear lsit,
>
>I have the following function plus specification:
>
>-spec new(Seq_nums, DDS_filter) -> Cfrs when
>      Seq_nums :: nonempty_list(rtps:sequence_number()),
>      DDS_filter :: fun((rtps:sequence_number()) -> boolean()),
>      Cfrs :: nonempty_list(cfr()).
>
>new(Seq_nums, DDS_filter) ->
>    [#cfr{sequence_number = N, status = unsent,
>          is_relevant = not DDS_filter(N)}
>     || N <- Seq_nums].
>
>Dialyzer complains with:
>
>Invalid type specification for function rtps_cfr:new/2. The success 
>typing is ([],_) -> []
>
>The filter is an external function,
>What is wrong with the spec?
>

You should look at the call-site. There's a possibility that the only 
places that call the function use arguments that are lists of terms that 
don't match the sequence number type. In doing so, dialyzer "removes" 
the types with these as crashing (i.e. DDS_filter would raise an 
exception).

What is left is the set of empty lists (once all the filters are done) 
which only gives ([],_) -> []

That's at least my guess without seeing the calling code.


More information about the erlang-questions mailing list