Why doesn't dialyzer warn me?

Attila Rajmund Nohl attila.r.nohl@REDACTED
Fri Mar 13 18:02:47 CET 2020


Hello!

I looked at a largish codebase with full of dialyzer warnings due to
record values created via multiple functions and the temporary values
does not satisfy the type spec. It's essentially the same problem as
mentioned in this thread:
https://erlang-questions.erlang.narkive.com/i74Hlqbm/temporarily-violating-record-type-constraints-annoys-dialyzer

I applied the solution recommended by Dániel and the warnings went
away - however, I'm a little afraid that if I end up creating a
"wrong" record, dialyzer still won't warn me. So I created a minimal
example:

-module(mylib).

-export([foo/1, t/0]).

-record(bar, {one, two}).
-type bar() :: #bar{one :: integer(), two :: list()}.

-spec foo(integer()) -> bar().
foo(12)  ->
  #bar{two = []};
foo(X) when is_integer(X) ->
  #bar{one = X, two = []}.

-spec t() -> bar().
t() ->
  foo(12).

Dialyzer does not warn me that the t/0 function returns a value that
does not satisfy the typespec (the field `one` will have `undefined`
value, not an integer). What am I doing wrong?


More information about the erlang-questions mailing list