了解透析器结果

Understanding dialyzer result

我有以下功能:

-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.

当我 运行 透析器时,我得到以下输出:

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 []

我对透析器还很陌生,无法理解透析器的输出。我的理解是说函数的前 5 个子句不能匹配 [],但这是我故意的,因为我匹配第六个子句中的空列表。

我的erlang版本是Erlang/OTP19.0,我的dialyzer版本是v3.0。

一个有趣的发现是,当我在另一台机器上 运行 dialyzer v2.8 和 Erlang/OTP 18 时,dialyzer 不会抱怨上面的代码。

到目前为止我尝试过的事情:

提前致谢

透析器警告的原因是由于我的代码存在缺陷,该函数总是使用空列表 ([]) 调用。

所以总结一下:Dialyzer 这次也没有错:)