在我学习灵药的过程中使用一个非常简单的应用程序时,我在用透析器检查类型时遇到了一个小问题。在我的代码上运行透析器会导致Analysis failed
错误...到目前为止,当我违反类型规范时透析器只给了我警告而不是错误,所以我不知道错误是什么。
试图缩小问题的范围,我制作了一个超简单的函数来执行有问题的返回值。
@spec blabla(integer) :: %{atom => any}
def blabla(1) do
%{:error => 'wrong input (US-state)'}
end
def blabla(2) do
%{ location: 'New York City, Central Park, NY', temp_c: '23.3',
visibility_mi: '10.00', weather: 'A Few Clouds', wind_dir: 'North',
wind_kt: '0' }
end
在运行透析器时,我收到以下错误
Proceeding with analysis...
=ERROR REPORT==== 14-Jul-2015::17:26:55 ===
Error in process <0.31.0> with exit value: {function_clause,[{erl_types,t_form_to_string,[{type,12,map_field_assoc,{type,12,atom,[]},{type,12,any,[]}}],[{file,"erl_types.erl"},{line,4546}]},{erl_types,t_form_to_string_list,2,[{file,"erl_types.erl"},{line,4637}]},{erl_types,t_form_to_string...
dialyzer: Analysis failed with error:
{function_clause,[{erl_types,t_form_to_string,
[{type,12,map_field_assoc,
{type,12,atom,[]},
{type,12,any,[]}}],
[{file,"erl_types.erl"},{line,4546}]},
{erl_types,t_form_to_string_list,2,
[{file,"erl_types.erl"},{line,4637}]},
{erl_types,t_form_to_string,1,
[{file,"erl_types.erl"},{line,4634}]},
{erl_types,t_form_to_string,1,
[{file,"erl_types.erl"},{line,4590}]},
{dialyzer_contracts,contract_to_string_1,1,
[{file,"dialyzer_contracts.erl"},
{line,107}]},
{dialyzer_contracts,extra_contract_warning,6,
[{file,"dialyzer_contracts.erl"},
{line,712}]},
{dialyzer_contracts,picky_contract_check,7,
[{file,"dialyzer_contracts.erl"},
{line,686}]},
{dialyzer_contracts,get_invalid_contract_warnings_funs,5,
[{file,"dialyzer_contracts.erl"},
{line,654}]}]}
我是否以错误的方式定义了地图类型?或者这是透析器中的一些错误吗?
答案 0 :(得分:2)
您的代码或typespec没有任何问题。看起来像透析器错误,您可以尝试更新到最新版本的Erlang。