[erlang-questions] Temporarily violating record type constraints annoys dialyzer

Brujo Benavides elbrujohalcon@REDACTED
Tue Nov 13 13:52:27 CET 2018


Forgot to say that, in the case of my_fun, I do test it with stuff like 0 or -1 or something_that_is_not_even_an_integer… But dialyzer doesn’t complain, since the spec allows it.

(Sorry for the double-emailing)

Brujo Benavides <http://about.me/elbrujohalcon>



> On 13 Nov 2018, at 09:49, Brujo Benavides <elbrujohalcon@REDACTED> wrote:
> 
> I generally tend to follow the rule that people (users of my libs, in particular) should use dialyzer themselves.
> So, for instance, if the the spec says this function should be called with a positive_integer(), I don’t test it with 0.
> If anybody tries to use the function with the wrong input… something that will trigger a warning from dialyzer… they should detect it when running dialyzer on their code.
> 
> So, no… I don’t do negative tests, in that sense.
> 
> On the other hand, if I have a function like…
> 
> my_fun(X) when X > 0 -> work_with(X);
> my_fun(X) -> error({invalid_input, X}).
> 
> I don’t spec it as…
> -spec my_fun(pos_integer()) -> ….
> 
> I spec it as…
> -spec my_fun(pos_integer()) -> …
>      ; my_fun(X) -> no_return().
> 
> (or something similar, I typed that off-the-top-of-my-head)
> 
> Brujo Benavides <http://about.me/elbrujohalcon>
> 
> 
> 
>> On 13 Nov 2018, at 09:44, Fred Hebert <mononcqc@REDACTED <mailto:mononcqc@REDACTED>> wrote:
>> 
>> On 11/13, Brujo Benavides wrote:
>>> Funny… I do exactly the opposite thing.
>>> 
>>> Since many of my projects are libraries and dialyzer is mostly clueless on the correctness of exported function specs when it has no other code using them, I use the tests to let dialyzer know how the functions are meant to be used. That way it can tell me if my specs are wrong or if something I meant to do with those functions is actually not possible.
>>> 
>>> That’s why, more often than not, instead of `rebar3 dialyzer`, I do `rebar3 as test dialyzer`.
>>> 
>>> BTW, I don’t think Krzysztof was saying that he run dialyzer against tests, just that (on one hand) tests pass but (on the other hand) when he checked his code with dialyzer, it complained. Mostly because I can see how dialyzer would complain with just his code, and no tests :)
>>> 
>>> Cheers
>>> 
>>> Brujo Benavides <http://about.me/elbrujohalcon <http://about.me/elbrujohalcon>>
>>> 
>> 
>> Do you just not do negative tests or you silence each of them individually?
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181113/742b685d/attachment.htm>


More information about the erlang-questions mailing list