[erlang-questions] Dialyzer warning about patterns

Kostis Sagonas kostis@REDACTED
Tue Jul 9 08:31:22 CEST 2013


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



More information about the erlang-questions mailing list