[erlang-questions] Dialyzer and try/after

Richard Carlsson richardc@REDACTED
Tue Aug 12 11:45:38 CEST 2008


Paul Guyot wrote:
> I have yet another issue with dialyzer. It seems that it is too  
> optimistic about the values of variables in an after clause:
> [...}
> 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

We have identified the problem, which has more to do with how the
compiler currently handles the code in the "after" block. We will
try to improve this as soon as we can, but we can't guarantee that
the fix gets in to the next release of OTP, which I think is due
fairly soon.

Meanwhile, the workaround is to manually lift the after...end
part to a separate function; in your case:

    ...
    after
        do_after(FooResult)
    end,
    Result.

do_after(FooResult) ->
      case FooResult of
        {ok, _} ->
          case foo_finalize(FooResult) of
            ok -> ignore;
            FinalizeError -> throw({barError, FinalizeError})
          end;
        _ ->
          io:format("_ can match.~n")
      end

Hope this works for you.

   /Richard

-- 
  "Having users is like optimization: the wise course is to delay it."
    -- Paul Graham



More information about the erlang-questions mailing list