[erlang-questions] Dialyzer warning on pattern match with sub-record

Russell Brown russell@REDACTED
Thu Mar 30 11:32:56 CEST 2017


Hi Stavros,
Thanks for the reply.


On 30 Mar 2017, at 09:53, Stavros Aronis <aronisstav@REDACTED> wrote:

> Hi Russell,
> 
> From your original warning:
> 
> On Thu, Mar 30, 2017 at 9:04 AM, Russell Brown <russell@REDACTED> wrote:
> riak_kv_vnode.erl:2695: Matching of pattern State = {'state', _, _, _, _, _, VId, _, _, _, _, _, _, _, _, _, _, _, _, _, {'counter_state', 'false', _, _, _, _}, _, _} tagged with a record name violates the declared type of #state{idx::'undefined' | integer(),mod::atom() | tuple(),async_put::'false' | 'true' | 'undefined',vnodeid::'undefined' | binary(),delete_mode::'immediate' | 'keep' | 'undefined' | pos_integer(),bucket_buf_size::'undefined' | pos_integer(),index_buf_size::'undefined' | pos_integer(),key_buf_size::'undefined' | pos_integer(),async_folding::'false' | 'true' | 'undefined',in_handoff::boolean(),handoff_target::atom(),handoffs_rejected::integer(),forward::atom() | [{integer(),atom()}],hashtrees::'undefined' | pid(),upgrade_hashtree::boolean(),md_cache::atom() | tid(),md_cache_size::'undefined' | pos_integer(),counter::'undefined' | #counter_state{use::'true',cnt::non_neg_integer(),lease::non_neg_integer(),lease_size::non_neg_integer(),leasing::boolean()},status_mgr_pid::'undefined' | pid(),update_hook::atom() | tuple()}
>   riak_object:object/0
> 
> my guess would be that in the definition of the #state record, the annotated #state.counter field's type is a #counter_state record whose #counter_state.use field annotated type is just the atom 'true'.
> 
> Can you send some context from that part of the module? (e.g. definition of #state and #counter_state records)

The record definition for #counter_state is:

-record(counter_state, {
         use = true :: boolean(),
         cnt = 0 :: non_neg_integer(),
         lease = 0 :: non_neg_integer(),
         lease_size = 0 :: non_neg_integer(),
         leasing = false :: boolean()
        }).

The #state record:
-record(state, {idx :: partition(),
                mod :: module(),
                async_put :: boolean(),
                modstate :: term(),
                mrjobs :: term(),
                vnodeid :: undefined | binary(),
                delete_mode :: keep | immediate | pos_integer(),
                bucket_buf_size :: pos_integer(),
                index_buf_size :: pos_integer(),
                key_buf_size :: pos_integer(),
                async_folding :: boolean(),
                in_handoff = false :: boolean(),
                handoff_target :: node(),
                handoffs_rejected = 0 :: integer(),
                forward :: node() | [{integer(), node()}],
                hashtrees :: pid(),
                upgrade_hashtree = false :: boolean(),
                md_cache :: ets:tab(),
                md_cache_size :: pos_integer(),
                counter :: #counter_state{},
                status_mgr_pid :: pid(), %% a process that manages vnode status persistence
                update_hook = riak_kv_noop_update_hook :: update_hook()
               }).

What I’m _most_ confused about is how the change of return type for that function surfaced this dialyzer warning.

Thanks again for your time

Russell

> 
> Best,
> 
> Stavros




More information about the erlang-questions mailing list