[erlang-questions] How to force dialyzer that a function will return?

Robert Raschke rtrlists@REDACTED
Sat Oct 13 23:11:22 CEST 2018


When you comment out your nowarn directive, you indeed get told

dt.erl:11: The call erlang:element(2,Dict::dict:dict(_,_)) contains an
opaque term as 2nd argument when terms of different types are expected in
these positions

which I'm guessing, is what your real code also gets?

I don't think it will be possible to let dialyzer think otherwise. So I
would suggest making whatever type you're dealing with non opaque. Or fix
the code to not look inside an opaque type :-)

Cheers, Robby



On Sat, 13 Oct 2018 18:37 Peti Gömöri, <gomoripeti@REDACTED> wrote:

> Hi Robby,
>
> While violation of opacity of data types is a bad, bad thing to do, it
> wont necessarily result in a crash at runtime. I guess that dialyzer by
> default infers that inner() function's return success type is none()
> because of the opacity violation, but I would like to override this, to
> allow inner() to return something (any()). This way I could check
> discrepancies in other parts of outer() function (and transitively the
> whole application)
>
> thanks
> Peter
>
> On Sat, Oct 13, 2018 at 4:57 PM Robert Raschke <rtrlists@REDACTED>
> wrote:
>
>> Hi Peti,
>>
>> that dialyzer warning usually really means what it says, unfortunately
>> without pointing out where exactly the path is that leads to "no return".
>> In my experience, it is worth investigating where your code may end up with
>> an error that leads to a crash. And not try to silence the warning.
>>
>> Cheers,
>> Robby
>>
>>
>> On Sat, 13 Oct 2018 15:01 Peti Gömöri, <gomoripeti@REDACTED> wrote:
>>
>>> Hi,
>>>
>>> Let's say I have a function that does a bad thing, but I now it will
>>> actually return. I can use the `-dialyzer` module attribute to silence the
>>> warning about the particular function, but is there any way to convince
>>> dialyzer to ignore that warning and assume that the function will return
>>> (and consequently all other functions calling it will also return).
>>>
>>> For example for the below module dialyzer still warns:
>>> dt.erl:6: Function outer/0 has no local return
>>>
>>> ```
>>> -module(dt).
>>>  -export([outer/0]).
>>>
>>> -dialyzer({nowarn_function, inner/0}).
>>>
>>> outer() ->
>>>     inner().
>>>
>>> inner() ->
>>>     Dict = dict:new(),
>>>     element(2, Dict).
>>> ```
>>>
>>> (this is just an example, I dont want to decompose a dict)
>>>
>>> thanks
>>> Peter
>>> _______________________________________________
>>> 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/20181013/904cc4ce/attachment.htm>


More information about the erlang-questions mailing list