Re: Dialyzer warning when returning a prolist
Fernando Benavides <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CA+yhPj6+-g7WeF0Cm=U4aWV4ZbQmGomaqVKp1hbF51Zfmq8bVg@mail.gmail.com> |
Probably because proplists:proplist() is not in your PLT. Have you tried enabling the unknown warning for dialyzer? It will likely tell you that it doesn't know the proplists:proplist/0 type. On Mon, 17 May 2021 at 22:25 Paulo Zulato <[email protected]> wrote: > Hello, > > I'm trying to figure out why dialyzer is complaining about a function when > I don't explicitly declare its return as a proplist. > I have this small module which returns a proplist in the form {atom(), > [atom()]}: > >> -module(test). >> >> -export([test/0]). >> test() -> >> [ >> {one_test, [a,b,c]}, >> {another_test, [d,e,f]} >> ]. >> > > For function above, I made the following spec, but dialyzer has complained > (as stated below) when I enabled its underspecs warnings. > >> -spec test() -> [{atom(), [atom()]}]. >> % src/test.erl >> % Type specification test:test() -> [{atom(),[atom()]}] is a supertype >> of the success typing: test:test() -> [{'another_test',['d' | 'e' | >> 'f',...]} | {'one_test',['a' | 'b' | 'c',...]},...] >> > > Well... both lists are non-empty lists as stated by dialyzer, so I > modified the spec, without success: > >> -spec test() -> [{atom(), [atom(), ...]}, ...]. >> %src/test.erl >> % Type specification test:test() -> [{atom(),[atom(),...]},...] is a >> supertype of the success typing: test:test() -> [{'another_test',['d' | 'e' >> | 'f',...]} | {'one_test',['a' | 'b' | 'c',...]},...] >> > > Then I tried to explicitly declare it as a proplist, and dialyzer has > accepted it: > >> -spec test() -> proplists:proplist(). >> % OK, no warnings. >> > > As it worked, I tried to do the same as proplists module does and created > two types, which I used on my new spec. And, surprisingly, dialyzer has > complained about it! > >> % From <https://erlang.org/doc/man/proplists.html> >> -type property() :: atom() | tuple(). >> -type proplist() :: [property()]. >> > >> -spec test() -> proplist(). >> %src/test.erl >> > % Type specification test:test() -> proplist() is a supertype of the >> success typing: test:test() -> [{'another_test',['d' | 'e' | 'f',...]} | >> {'one_test',['a' | 'b' | 'c',...]},...] >> > > Therefore, I could not understand why declaring the return as > "proplists:proplist" is OK while declaring it as lists, nonempty lists or > creating the same types as proplists are not OK. Why is dialyzer > complaining about the other specs? Is dialyzer handling proplists in a > different way? Could someone help me to understand this behaviour? > > > Best Regards, > Paulo Zulato > > -- > «Quis custodiet ipsos custodes?» > -- Sent from Gmail Mobile by Brujo Benavides