possible dialyzer bug

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

possible dialyzer bug

Zachary Kessin-2
I have a strange dialyzer problem, I have this code

                  case convert_map_to_record(MapId, UserId, ClientId, Terms) of
                      {ok, MapRecord} ->
                          %....
                          {true, ReqData1, MapRecord};
                      {error, Error} ->
                          lager:error("Error ~p", [Error]),
                          {{error, 405}, ReqData, State}
                  end

and dialyzer is saying this

_build/default/lib/frontend/src/wm_map.erl
 100: The pattern {'ok', MapRecord} can never match the type {'error',_}

With what is line 100 being the line with the red background, what is strange is that that the error case is covered in the case statement

Zach
--
Zach Kessin
Twitter: @zkessin
Skype: zachkessin

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: possible dialyzer bug

Brujo Benavides-2
Zach:

Dialyzer is basically telling you that, with the parameters you’re using MapId, UserId, ClientId, Terms), the function convert_map_to_record/4 can never return {ok, _}.
Without the code preceding the function call and the code for convert_map_to_record/4, it’ll be hard to tell you exactly what’s going on.
Cheers!

On Jan 25, 2016, at 11:09, Zachary Kessin <[hidden email]> wrote:

I have a strange dialyzer problem, I have this code

                  case convert_map_to_record(MapId, UserId, ClientId, Terms) of
                      {ok, MapRecord} ->
                          %....
                          {true, ReqData1, MapRecord};
                      {error, Error} ->
                          lager:error("Error ~p", [Error]),
                          {{error, 405}, ReqData, State}
                  end

and dialyzer is saying this

_build/default/lib/frontend/src/wm_map.erl
 100: The pattern {'ok', MapRecord} can never match the type {'error',_}

With what is line 100 being the line with the red background, what is strange is that that the error case is covered in the case statement

Zach
--
Zach Kessin
Twitter: @zkessin
Skype: zachkessin
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: possible dialyzer bug

Kostis Sagonas-2
In reply to this post by Zachary Kessin-2
On 01/25/2016 03:09 PM, Zachary Kessin wrote:

> I have a strange dialyzer problem, I have this code
>
>                    case convert_map_to_record(MapId, UserId, ClientId,
> Terms) of
>                        {ok, MapRecord} ->
>                            %....
>                            {true, ReqData1, MapRecord};
>                        {error, Error} ->
>                            lager:error("Error ~p", [Error]),
>                            {{error, 405}, ReqData, State}
>                    end
>
> and dialyzer is saying this
>
> _build/default/lib/frontend/src/wm_map.erl
>   100: The pattern {'ok', MapRecord} can never match the type {'error',_}
>
> With what is line 100 being the line with the red background, what is
> strange is that that the error case is covered in the case statement

Yes, what dialyzer tells you is that it has somehow inferred that your
convert_map_to_record/4 function only returns {'error',_}, so the
{'ok',_} pattern will never match.

Most likely, your convert_map_to_record/4 function does not do what you
think it does...  For more info, please submit a complete module that
illustrates the problem.

Kostis
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: possible dialyzer bug

Jesper Louis Andersen-2
In reply to this post by Zachary Kessin-2

On Mon, Jan 25, 2016 at 3:09 PM, Zachary Kessin <[hidden email]> wrote:
I have a strange dialyzer problem, I have this code

You would have to supply the convert_map_to_record function as well. Usually the case is that the dialyzer has figured out, one way or the other, that there is only a single possible outcome of convert_map_to_record: {error, _}. Hence it reports that {ok, MR} can never match, which is true.

This commonly happens when you have a planned extension later in the code base, and have provided scaffolding for the extension, yet the underlying code is not able to touch that newly formed code path yet because it doesn't return the correct type of value.

Another common case is where there is another error somewhere in your code and the dialyzer has figured out that with the current constraints, convert_map_to_record can only succeed without crashing by returning {error, _}.  This can happen if the record spec is not precise enough, for instance.



--
J.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions