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:
- I'm not very experienced with binaries in erlang so my initial thought was that I had misunderstood the binary pattern matching, but this seems not to be the case. The function passes my test cases (calling the function with [] as parameter is no problem), and also if I replace the binaries with normal strings in the function heads I get the same complaints by dialyzer.
- Rebuilt the plt and cleaned the project
Thanks in advance
1条答案
按热度按时间33qvvth11#
透析器警告的原因是,由于我的代码中存在缺陷,始终使用空列表(
[]
)调用该函数。因此得出结论:透析器这次也没有错:)