gen_statem:start_monitor dialyzer warning

Raimo Niskanen raimo+erlang-questions@REDACTED
Mon Jan 25 12:52:40 CET 2021


On Sun, Jan 24, 2021 at 02:31:54PM +0100, Kostis Sagonas wrote:
> On 1/24/21 2:14 PM, Matt Kowalczyk wrote:
> > Having a hard time understanding why the following sample code generates 
> > a dialyzer warning,
> 
> Either because somebody added wrong specs to 'gen_statem' or forgot to 
> update the specs of 'gen'.

There is room for improvement here.

We have a few Issues reported to bugs.erlang.org regarding type exports
from gen_server and gen_statem, and internal discussions have not completed
on how much types that would be useful to export...

Here gen does not export the right type for gen:start(_, monitor, ...).
I am not sure that we should specify types in gen; it is an internal module,
so maybe it would be better to rely on Dialyzer figuring them out instead...

Also gen_statem exports start_ret() but not start_mon_ret().  That is not
consistent.

Cheers
/ Raimo


> 
> 
> ===== gen_statem has these types and specs =====
> 
> -type start_mon_ret() ::
>          {'ok', {pid(),reference()}}
>        | 'ignore'
>        | {'error', term()}.
> 
> -spec start_monitor(
> 	Module :: module(), Args :: term(), Opts :: [start_opt()]) ->
> 		   start_mon_ret().
> start_monitor(Module, Args, Opts) ->
>      gen:start(?MODULE, monitor, Module, Args, Opts).
> 
> 
> ===== gen:start/5's return type is: ======
> 
> -type start_ret()  :: {'ok', pid()} | 'ignore' | {'error', term()}.
> 
> 
> Their intersection is: 'ignore' | {'error', term()}.
> 
> 
> Dialyzer is never wrong (C), but wrong specs can cause confusion.
> 
> Kostis

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list