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

Loïc Hoguin <>
Fri Apr 18 12:00:58 CEST 2014


On 04/18/2014 11:55 AM, Dániel Szoboszlay wrote:
> 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.

I am not sure what you mean by that. I have been doing it for a long 
time and it works just fine, albeit I always use opaque for exported 
records.

> Regards,
> Daniel
>
> On 2014 Apr 18, at 11:40 , Solomon <
> <mailto:>> 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
>>  <mailto:>
>> http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list