[erlang-questions] Why does Dialyzer crash on this map?

Ali Sabil ali.sabil@REDACTED
Thu Apr 9 17:21:19 CEST 2015


Sorry for the late reply, I finally managed to get a minimal test case that
reproduces the bug in 17.5:

-module(sum).
-export([
test/1
]).

-spec test(#{atom() => term()}) -> integer().
test(Data) ->
maps:fold(fun
(_Key, Value, Acc) when is_integer(Value) ->
Acc + Value;
(_Key, _Value, Acc) ->
Acc
end, 0, Data).


I don't know if this is the correct fix, but this makes dialyzer work again:

diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl
index 4215448..bb4c1c1 100644
--- a/lib/hipe/cerl/erl_types.erl
+++ b/lib/hipe/cerl/erl_types.erl
@@ -4594,6 +4594,8 @@ t_form_to_string({type, _L, list, [Type]}) ->
   "[" ++ t_form_to_string(Type) ++ "]";
 t_form_to_string({type, _L, map, Args}) when not is_list(Args) ->
   "#{}";
+t_form_to_string({type, _L, map_field_assoc, Key, Value}) ->
+  "#{" ++ t_form_to_string(Key) ++ "=>" ++ t_form_to_string(Value) ++ "}";
 t_form_to_string({type, _L, mfa, []}) -> "mfa()";
 t_form_to_string({type, _L, module, []}) -> "module()";
 t_form_to_string({type, _L, node, []}) -> "node()";

Thanks,
Ali

On Tue, Apr 7, 2015 at 2:31 PM Björn-Egil Dahlberg <
wallentin.dahlberg@REDACTED> wrote:

> Again - could you provide me with a sample code .. or at least some sort
> of a clue to what you are dialyzing?
>
> 2015-04-07 14:05 GMT+02:00 Ali Sabil <ali.sabil@REDACTED>:
>
>> Hi again,
>>
>> Running dialyzer shipped with 17.5 on the same code base leads now to the
>> following error (17.4 works without any errors):
>>
>> ===> Error in dialyzing apps: Analysis failed with error:
>> {function_clause,[{erl_types,t_form_to_string,
>>                              [{type,36,map_field_assoc,
>>                                     {type,36,atom,[]},
>>                                     {type,36,term,[]}}],
>>                              [{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_list,2,
>>                              [{file,"erl_types.erl"},{line,4637}]},
>>                   {erl_types,t_form_to_string,1,
>>                              [{file,"erl_types.erl"},{line,4634}]},
>>                   {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}]}]}
>> Last messages in the log cache:
>>   Reading files and computing callgraph... done in 1.21 secs
>>   Removing edges... done in 0.04 secs
>>
>>
>> On Wed, Mar 18, 2015 at 12:12 PM Björn-Egil Dahlberg <egil@REDACTED>
>> wrote:
>>
>>> On 2015-03-18 12:01, Ali Sabil wrote:
>>> > I tried to create a minimal testcase but I unfortunately haven't been
>>> > able to. I was running dialyzer on a quite large code base and now
>>> > even the unpatched dialyzer works without any issue after I fixed all
>>> > the issues reported by dialyzer.
>>>
>>> Ah, well .. I suspect it was the missing clause in find_terminals and I
>>> had it on a TODO somewhere. Should be included to 17.5.
>>>
>>> // Björn-Egil
>>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150409/4de8348c/attachment.htm>


More information about the erlang-questions mailing list