Erlang dialyzer warnings for internal functions.

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

Erlang dialyzer warnings for internal functions.

WW-2
Sorry for disturbing Frank!
Now the new thread for discussion of dialyzer issues ..........

Hi guys I have moved dialyzer discussions on this thread, so we can continue here!


Code example
=======================================================
-module(helloworld).
-export([start/0]).
%%-export([validator/1]).

start()->
    try
        validator(undefined),
        validator([]),
        validator(3)
    catch
          exit:Reason->
              {error, Reason}    
    end.

%%%###=======================================================================###
-spec validator(X::any())->no_return().
%%%###=======================================================================###          
validator([])->
exit({error, "empty list"});            
           
validator(undefined) ->
exit({error, undefined});

validator(_Any)->
exit({error,"unknown"}).

=========================================================================================
When function in module validator/1 is not exported, dialyzer gives warnings.
 Checking whether the PLT /home/eweiwan/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
helloworld.erl:18: The pattern [] can never match the type 'undefined'
helloworld.erl:24: The variable _Any can never match since previous clauses completely covered the type 'undefined'
 done in 0m1.45s
done (warnings were emitted)   <<<<<<<<<<<<<<<<<<<<<<<<<<
-------------------------------------------------------------------------------------------------------------------------------------------------
When function is exported, dialyzer result :

 Checking whether the PLT /home/eweiwan/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis... done in 0m1.55s
done (passed successfully)    <<<<<<<<<<<<<<<<<<<<<<<<<<<<
---------------------------------------------------------------------------------------------------------------------------------------------------

What is the best solution to avoid dialyzer warnings meanwhile also satisfy my use cases.?

Thank you
BR//Wei





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

Re: Erlang dialyzer warnings for internal functions.

Kostis Sagonas-2
On 4/28/19 6:41 PM, WW wrote:
>
> What is the best solution to avoid dialyzer warnings meanwhile also
> satisfy my use cases.?
>

One cannot really answer this question without knowing what your "use
case(s)" really is.,,,

If it really is the code example you posted, if you pay close attention
to the warning that you get from dialyzer, dialyzer also tells you that
the call validator([]), let alone validator(3), is actually unreachable
code in your example.  This is because dialyzer discovers that the prior
call (validator(undefined)) will throw an exit exception and
control-flow will never reach the validator([]) (and validator(3)) calls.

Once again, remember the slogan: "Dialyzer is never wrong."

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

Re: Erlang dialyzer warnings for internal functions.

WW-2
Why dialyzer did not complain when  I  exported the function validator/1 ?

It means exported function allowing never reach the calls ?


On Sunday, April 28, 2019, 9:30:03 PM GMT+2, Kostis Sagonas <[hidden email]> wrote:


On 4/28/19 6:41 PM, WW wrote:

>
> What is the best solution to avoid dialyzer warnings meanwhile also
> satisfy my use cases.?

>

One cannot really answer this question without knowing what your "use
case(s)" really is.,,,

If it really is the code example you posted, if you pay close attention
to the warning that you get from dialyzer, dialyzer also tells you that
the call validator([]), let alone validator(3), is actually unreachable
code in your example.  This is because dialyzer discovers that the prior
call (validator(undefined)) will throw an exit exception and
control-flow will never reach the validator([]) (and validator(3)) calls.

Once again, remember the slogan: "Dialyzer is never wrong."

Kostis


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

Re: Erlang dialyzer warnings for internal functions.

Guilherme Andrade
Hello Wei,

On Sun, 28 Apr 2019 at 21:38, WW <[hidden email]> wrote:
Why dialyzer did not complain when  I  exported the function validator/1 ?

It means exported function allowing never reach the calls ?

Because when you export said function, Dialyzer can't assume it won't be called from code outside its analysis scope (e.g. modules in uncovered apps, modules loaded in runtime, function references generated in run time, the shell, ..) and so it can't determine the full range of possible arguments - anything goes. And if anything goes, there's no way of saying: "this particular execution flow will never happen."

Which is usually not the case with internal functions, where all possible calling arguments /may/ be known when performing analysis, depending on your code and how precisely Dialyzer can track type constraints in it.

 


On Sunday, April 28, 2019, 9:30:03 PM GMT+2, Kostis Sagonas <[hidden email]> wrote:


On 4/28/19 6:41 PM, WW wrote:

>
> What is the best solution to avoid dialyzer warnings meanwhile also
> satisfy my use cases.?

>

One cannot really answer this question without knowing what your "use
case(s)" really is.,,,

If it really is the code example you posted, if you pay close attention
to the warning that you get from dialyzer, dialyzer also tells you that
the call validator([]), let alone validator(3), is actually unreachable
code in your example.  This is because dialyzer discovers that the prior
call (validator(undefined)) will throw an exit exception and
control-flow will never reach the validator([]) (and validator(3)) calls.

Once again, remember the slogan: "Dialyzer is never wrong."

Kostis

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


--
Guilherme

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

Re: Erlang dialyzer warnings for internal functions.

WW-2
Thank you, Guilhenrme!

Here is my conclusion:

For internal function call, we need actually implement to cover all cases specified in the function (missing implementation dialyzer will give warning), however, when exporting that function, dialyzer  can't determine the full range of possible arguments, so it will not give warning. 

solution:  1) Export that function.
                2) Switch off  thedialyzer warning for that function: -dialyzer({nowarn_function, validator/1}).



Best regards //Wei. W

On Sunday, April 28, 2019, 11:19:26 PM GMT+2, Guilherme Andrade <[hidden email]> wrote:


Hello Wei,

On Sun, 28 Apr 2019 at 21:38, WW <[hidden email]> wrote:
Why dialyzer did not complain when  I  exported the function validator/1 ?

It means exported function allowing never reach the calls ?

Because when you export said function, Dialyzer can't assume it won't be called from code outside its analysis scope (e.g. modules in uncovered apps, modules loaded in runtime, function references generated in run time, the shell, ..) and so it can't determine the full range of possible arguments - anything goes. And if anything goes, there's no way of saying: "this particular execution flow will never happen."

Which is usually not the case with internal functions, where all possible calling arguments /may/ be known when performing analysis, depending on your code and how precisely Dialyzer can track type constraints in it.


 


On Sunday, April 28, 2019, 9:30:03 PM GMT+2, Kostis Sagonas <[hidden email]> wrote:


On 4/28/19 6:41 PM, WW wrote:

>
> What is the best solution to avoid dialyzer warnings meanwhile also
> satisfy my use cases.?

>

One cannot really answer this question without knowing what your "use
case(s)" really is.,,,

If it really is the code example you posted, if you pay close attention
to the warning that you get from dialyzer, dialyzer also tells you that
the call validator([]), let alone validator(3), is actually unreachable
code in your example.  This is because dialyzer discovers that the prior
call (validator(undefined)) will throw an exit exception and
control-flow will never reach the validator([]) (and validator(3)) calls.

Once again, remember the slogan: "Dialyzer is never wrong."

Kostis

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


--
Guilherme


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