Dialyzer and throw/catch

Gordon Guthrie gordon@REDACTED
Sat Dec 4 21:52:27 CET 2010


Folks

I am getting a dialyzer error that doesn't seem write.

Here is the code:

            case Value of
                R when ?is_cellref(R) ->
                    case muin_util:attempt(?MODULE, fetch, [R]) of
                        {ok,    blank}              -> 0;
                        {error, {aborted, _} = Err} -> exit(Err);
                        {ok,    Other}              -> Other;
                        {error, ErrVal}             -> ErrVal
                    end;

It call the function muin_util:attempt/3 which looks like:

attempt(Mod, F, Args) ->
    try apply(Mod, F, Args) of
        Val -> {ok, Val}
    catch
        Error:Reason when Error =:= error orelse Error =:= throw ->
            error_logger:error_msg({Error, Reason,
erlang:get_stacktrace()}),
            {error, Reason}
    end.

Dialyzer gives the following warning:

muin.erl:88: The pattern {'error', Err = {'aborted', _}} can never match the
type {'ok',_}
muin.erl:90: The pattern {'error', ErrVal} can never match the type {'ok',_}
muin.erl:134: The pattern {'error', Err = {'errval', _}} can never match the
type {'ok',_}
muin.erl:135: The pattern {'error', Err = {'aborted', _}} can never match
the type {'ok',_}
muin.erl:136: The pattern {'error', _E} can never match the type {'ok',_}

The function attempt/3 can return both the {'error', ...} patterns it
objects to, from the catch...

Am I missing something?

Gordon

-- 
Gordon Guthrie
CEO hypernumbers

http://hypernumbers.com
t: hypernumbers
+44 7776 251669


More information about the erlang-questions mailing list