[erlang-questions] Dialyzer and List Type

PhayTsukiming moonsolo@REDACTED
Tue Apr 19 10:27:25 CEST 2016


On Tue, Apr 19, 2016 at 4:08 PM Kostis Sagonas <kostis@REDACTED> wrote:

> On 04/19/2016 08:50 AM, PhayTsukiming wrote:
> >
> > Then apply dialyzer to this module and dialyzer warns:
> >
> > t.erl:8: Invalid type specification for function t:bar/1. The success
> > typing is ([integer()]) -> [integer()]
> >
> > But if I change the specification of bar to:
> >
> > -spec bar([atom()])->[integer()].
> >
> > dialyzer will show no warnings. My intention is to make sure the
> > argument of bar is the same type of list as the argument of foo.
>
> OK, but then why don't you put the same spec there?  Is there any
> problem in this case?
>

Sorry, I forgot to mention that I was experimenting with my understanding
of dialyzer. In the beginning, I thought type specification in erlang works
as just the same as in other static type language.

So I used -spec bar(atom())->[integer()] then dialyzer complained. This
worked as expected.

But when I used -spec bar([atom()])->[integer()], then dialyzer didn't say
a word and in static type languages, similar specifications would cause the
compiler to generate errors.

>
> > Is this normal? Do I miss or misunderstand something about success
> > typing or dialyzer?
>
> Yes, you do.  All that dialyzer ever promised is that when it spits a
> warning then this warning is correct.  (This is the "Dialyzer is never
> wrong" slogan.)
>
> On the other hand, it never promised to produce warnings in all cases
> you may expect it to do so.
>
> Kostis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160419/92f97bc6/attachment.htm>


More information about the erlang-questions mailing list