[erlang-questions] Dialyzer and try/after

Paul Guyot pguyot@REDACTED
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:

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

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

foo(Atom) ->
   case Atom of
     error -> error;
     _ -> {ok, Atom}

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

foobar(ok) -> ok;
foobar(_) -> error.

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}}, 

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  


More information about the erlang-questions mailing list