[erlang-questions] the record volates the declared type when I analysis the code

Dániel Szoboszlay dszoboszlay@REDACTED
Fri Apr 18 11:55:51 CEST 2014


Hi,

I’d recommend you to decouple the type spec from the record the following way:

-record(kv, {key, value}).
-type kv() :: #kv{key::string(), value::integer()}.

Bonus feature: you can export the kv/0 type from your module (if you need to), but you can’t do that when the types are embedded into the record declaration.

Regards,
Daniel

On 2014 Apr 18, at 11:40 , Solomon <solomon.wzs@REDACTED> wrote:

> Hi.
> 
> I declared a record like this:
> -record(kv, {key::string(), value::integer()}).
> 
> and I create a mnesia table to save the record 'kv'
> 
> I select the table like this:
> mnesia:dirty_select(table, [{#kv{key='_', value='$1'}, [{'>', '$1',
> 10}], ['_']}]).
> 
> then I analysis the code:
> dialyzer --plt ./.depsolver_plt ./ebin/my.beam
> 
> and I get the error:
> Record construction #kv{key::'_', value::'$1'} violates the declared
> type of field key::string() and value::integer()
> 
> How should I fix the error?
> 
> Thanks.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140418/7d4a3b95/attachment.htm>


More information about the erlang-questions mailing list