"dialyzer: Analysis failed with error.."(透析器错误?还是错误地使用地图类型?)



在我学习elixir的过程中,我在一个非常简单的应用程序上工作,当我用透透器检查类型时,我遇到了一个小障碍。在我的代码上运行透析器导致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}]}]}

我是否以错误的方式定义了映射类型?还是透析器里有虫子?

您的代码或类型说明没有问题。

最新更新