[erlang-bugs] 17.0 : dialyzer issue on boolean type in record.

Steve Vinoski vinoski@REDACTED
Tue Jul 29 00:25:20 CEST 2014


On Mon, Jul 28, 2014 at 5:56 PM, PAILLEAU Eric <eric.pailleau@REDACTED>
wrote:

> Hi,
> please considere below minimal module :
> ---8<----------------------------------------------------
> -module(test).
>
> -export([test/0]).
>
> -record(test, { bool   = 'true' :: boolean()} ).
>
> test() -> test(#test{}).
>
> test(R) -> case R#test.bool of
>                 true  -> ok ;
>                 false -> ok
>            end.
> ---8<----------------------------------------------------
> dialyzer raise an error :
>
> test.erl:11: The pattern 'false' can never match the type 'true'.
>
> Looks like dialyzer considere #test.bool to be of type 'true' while it is
> of type boolean() and default value to 'true'.
>
> Documentation says :
> "In the presence of initial values for fields, the type must be declared
> after the initialization as in the following:
>
>   -record(rec, {field1 = [] :: Type1, field2, field3 = 42 :: Type3}).
>
> Naturally, the initial values for fields should be compatible with (i.e. a
> member of) the corresponding types. "
>
>
> A bug, isn't it ?
>

I don't think it's a bug since the only way test/1 can be called is via
test/0, and the latter passes a #test{} record instance containing only
default values. In this case, the default value of the bool field is true,
so dialyzer is correct that false can never match.

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140728/84ecb131/attachment.htm>


More information about the erlang-bugs mailing list