[erlang-questions] dialyzer and #record vs tuple

Vincent de Phily <>
Fri Jun 7 10:50:27 CEST 2013


Hi List,

I'm doing a long-overdue set of dialyzer checks on our software, and have a 
few occurences of the following problem:

> % Define a record with a constrained field
> -record(foo, {bar = 0 :: integer()}).
>
> % Use the record, works as expected
> new_foo(Id) -> #foo{bar=Id}.
>
> % Use a similar-looking tuple, dialyzer complains about
> %     Record construction #foo{bar::true} violates the declared type of
> %     field bar::integer()
> default_options() -> [{foo, true}].

I understand why dialyzer gets confused, since it can't (?) differenciate 
between a "raw" tuple and a record. But at the semantic level, they really are 
different things, so changing the record definition to allow booleans doesn't 
really make sense.

How would you handle that kind of problem ? So far I have resorted to changing 
either the name of the record or the tag/arity of the tuple, but it generally 
feels wrong and inelegant, and later commits might inadvertantly reintroduce 
the natural-but-clashing tuple.


-- 
Vincent de Phily



More information about the erlang-questions mailing list