[erlang-questions] Dialyzer warning about patterns

Jonathan Leivent jleivent@REDACTED
Tue Jul 9 20:36:54 CEST 2013


On 07/09/2013 02:31 AM, Kostis Sagonas wrote:
> On 07/09/2013 09:06 AM, Yash Ganthe wrote:
>> Hi,
>>
>> I have the following code:
>>
>> Port = open_port({spawn,Args},[{packet,2}]),
>>
>> case is_port(Port) of
>>
>> true ->
>>
>> io:format("~n ~p port created successfully ~n",[Port]),
>>
>> ok;
>>
>> false -> %%Line 52
>>
>> io:format("something went wrong ~n"),
>>
>> failed
>>
>> end.
>>
>> Dialyzer gives the following warning:
>>
>> mymod.erl:52: The pattern 'false' can never match the type 'true'
>>
>> The possible results of is_port are true and false considering
>>
>> is_port(Term) -> boolean()
>>
>> What do I need to do to get rid of such warnings?
>
> You simplify your code by taking out the false branch of the case
> statement and the case statement itself.  Sorry to point it out, but in
> its current state the above code is moronic.
>
> Yes, is_port/1 returns boolean() but that's if you pass it any term(),
> not something that is clearly a port().
>
> Kostis

I have a related issue where the false branch of the case is only false 
because of the way a macro is defined.  If the macro is defined another 
way, the other branch is false.  So, I end up with this dialyzer warning 
just because I'm using a conditional that evaluates to a constant at 
preprocessing time.  I would think this is pretty common with macros 
like 'debug'.

Is there a way to tell dialyzer to ignore certain instances of warnings? 
  A way to add a comment on that line to tell dialyzer to ignore a 
particular problem on that line, for instance?

-- Jonathan




More information about the erlang-questions mailing list