[erlang-questions] Dialyzer

Frans Schneider fchschneider@REDACTED
Sun Jan 20 18:31:01 CET 2019


Yep, it were the nonempty lists which caused the problem. I used 
nonempty because _I_ know that the function never is called with an 
empty list, but that is not relevant for the specs of the function.

On 1/20/19 5:34 PM, Fred Hebert wrote:
> 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