[erlang-bugs] dialyzer does not like queue:out

Paul Guyot <>
Sat Jul 16 19:18:26 CEST 2011


Dialyzer seems to consider that the second element of the output of queue:out/1 is not a queue.

The following code reproduces the error:


-record(rec, {
    q :: queue()

-spec f(#rec{}) -> ok.
f(Rec) ->
    case g(Rec) of
        {ok, _Value, _NewRec} -> ok;
        {none, _NewRec} -> ok

g(#rec{q = Queue} = Rec) ->
    case queue:out(Queue) of
        {empty, _} -> {none, Rec};
        {{value, Elem}, NewQueue} -> {ok, Elem, #rec{q = NewQueue}}

Dialyzer will say:

dialyzer_queue.erl:11: The pattern {'ok', _Value, _NewRec} can never match the type {'none',#rec{q::queue()}}

The error disappears if g returns {ok, Elem, Rec} instead of {ok, Elem, #rec{q = NewQueue}}, or if rec.q is typed as any().

Semiocast            http://semiocast.com/
+33.183627948 - 20 rue Lacaze, 75014 Paris

More information about the erlang-bugs mailing list