erlangdialyzer

Understanding dialyzer result


I have the following function:

-spec check_connection_header(list()) -> atom().
check_connection_header([{<<"Connection">>, <<"close">>}|_]) ->
    close;

check_connection_header([{<<"Connection">>, <<"Close">>}|_]) ->
    close;

check_connection_header([{<<"connection">>, <<"close">>}|_]) ->
    close;

check_connection_header([{<<"connection">>, <<"Close">>}|_]) ->
    close;

check_connection_header([_|Rest]) ->
    check_connection_header(Rest);

check_connection_header([])->
    keep_alive.

And when i run dialyzer I get the following output:

131: The pattern [{<<67:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1,110:8/integer-unit:1,101:8/integer-unit:1,99:8/integer-unit:1,116:8/integer-unit:1,105:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1>>, <<99:8/integer-unit:1,108:8/integer-unit:1,111:8/integer-unit:1,115:8/integer-unit:1,101:8/integer-unit:1>>} | _] can never match the type []
 134: The pattern [{<<67:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1,110:8/integer-unit:1,101:8/integer-unit:1,99:8/integer-unit:1,116:8/integer-unit:1,105:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1>>, <<67:8/integer-unit:1,108:8/integer-unit:1,111:8/integer-unit:1,115:8/integer-unit:1,101:8/integer-unit:1>>} | _] can never match the type []
 137: The pattern [{<<99:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1,110:8/integer-unit:1,101:8/integer-unit:1,99:8/integer-unit:1,116:8/integer-unit:1,105:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1>>, <<99:8/integer-unit:1,108:8/integer-unit:1,111:8/integer-unit:1,115:8/integer-unit:1,101:8/integer-unit:1>>} | _] can never match the type []
 140: The pattern [{<<99:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1,110:8/integer-unit:1,101:8/integer-unit:1,99:8/integer-unit:1,116:8/integer-unit:1,105:8/integer-unit:1,111:8/integer-unit:1,110:8/integer-unit:1>>, <<67:8/integer-unit:1,108:8/integer-unit:1,111:8/integer-unit:1,115:8/integer-unit:1,101:8/integer-unit:1>>} | _] can never match the type []
 143: The pattern [_ | Rest] can never match the type []

I am pretty new to dialyzer and have trouble interpreting the output of dialyzer. I understand it is saying that the first 5 clauses of the function can't match [], but that is deliberate from my part since I'm matching the empty list in the sixth clause.

My erlang version is Erlang/OTP 19.0 and my dialyzer version is v3.0.

A interesting discover was that dialyzer does'nt complain about the above code when i run dialyzer v2.8 and Erlang/OTP 18 on another machine.

Things I've tried so far:

Thanks in advance


Solution

  • The reason for the dialyzer warnings was that the function was always called with empty list ([]) due to a defect in my code.

    So to conclude: Dialyzer was not wrong this time either :)