[erlang-questions] Dialyzer and try/after

Paul Guyot <>
Mon Aug 11 11:45:12 CEST 2008


Le 11 août 08 à 09:58, Tobias Lindahl a écrit :

>> Is it a known bug? Or is it a mistake in the way I specify the  
>> recursive type?
>
> It is a known limitation. We have not had the time to implement  
> recursive types yet, parametrized or not. Unfortunately, I cannot  
> give you a time estimate for this.

Dear Tobias,

Thank you very much for your reply!
I have yet another issue with dialyzer. It seems that it is too  
optimistic about the values of variables in an after clause:

----
-module(dialyzer_test).
-export([foo/1, bar/1, demo/0]).

-type(result() :: {ok, atom()}).
-type(result_or_error() :: result() | error).

-spec(foo/1::(atom())->result_or_error()).
foo(Atom) ->
   case Atom of
     error -> error;
     _ -> {ok, Atom}
   end.

-spec(bar/1::(atom())->atom()).
bar(Atom) ->
   FooResult = foo(Atom),
   Result = try
     case FooResult of
       {ok, Data} ->
         case foobar(Data) of
           ok -> ok;
           SomeError -> throw({barError, SomeError})
         end;
       Error -> throw({barError, Error})
     end
   after
     case FooResult of
       {ok, _} ->
         case foo_finalize(FooResult) of
           ok -> ignore;
           FinalizeError -> throw({barError, FinalizeError})
         end;
       _ ->
         io:format("_ can match.~n")
     end
   end,
   Result.

-spec(foobar/1::(atom())->any()).
foobar(ok) -> ok;
foobar(_) -> error.

-spec(foo_finalize/1::(tuple())->any()).
foo_finalize({ok, closed}) -> ok;
foo_finalize(_) -> error.

demo() -> bar(error).
----
 > dialyzer -r .
   Checking whether the PLT /Users/paul/.dialyzer_plt is up-to- 
date... yes
   Proceeding with analysis...
dialyzer_test.erl:33: The variable _ can never match since previous  
clauses completely covered the type {'ok',atom()}
Unknown functions:
  done in 0m1.86s
done (warnings were emitted)
----
 > erl -s dialyzer_test demo
Erlang (BEAM) emulator version 5.6.3 [source] [async-threads:0]  
[hipe] [kernel-poll:false]

_ can match.
{"init terminating in do_boot",{{nocatch,{barError,error}}, 
[{init,start_it,1},{init,start_em,1}]}}

Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
----

Is it a known limitation?
Unlike the recursive type, this is a blocker issue as I don't know  
how to alter the specification to avoid the dialyzer error. And I  
don't want to start ignoring dialyzer errors, the tool is way too  
useful.

Paul




More information about the erlang-questions mailing list