Re: 17.0 : dialyzer issue on boolean type in record.
Steve Vinoski <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.bugs |
|---|---|
| Message-ID | <CAO+zUOWi2_J6vSAeV0=6Z16oF3qoi0+K6H4fLkG+Yfgnvx5QTg@mail.gmail.com> |
On Mon, Jul 28, 2014 at 5:56 PM, PAILLEAU Eric <[email protected]> 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 _______________________________________________ erlang-bugs mailing list [email protected] http://erlang.org/mailman/listinfo/erlang-bugs