<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">30 марта 2017 г., в 11:12, Russell Brown <<a href="mailto:russell@wombat.me" class="">russell@wombat.me</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On 30 Mar 2017, at 09:08, Alex S. <</span><a href="mailto:alex0player@gmail.com" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">alex0player@gmail.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><br class="">30 марта 2017 г., в 11:06, Russell Brown <<a href="mailto:russell@wombat.me" class="">russell@wombat.me</a>> написал(а):<br class=""><br class=""><br class="">On 30 Mar 2017, at 09:00, Alex S. <<a href="mailto:alex0player@gmail.com" class="">alex0player@gmail.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">#counter_state{use::'true',cnt::non_neg_integer(),lease::non_neg_integer(),lease_size::non_neg_integer(),leasing::boolean()}<br class=""></blockquote><br class="">Dialyzer somehow figured out that counter_state is never constructed with ‘false’ (and has no explicit contract).<br class=""></blockquote><br class="">Thanks for the reply, there is a code path where counter state can be updated to have `use=false`. I’m sorry but I don’t know what “no explicit contract” means in this context, can you explain?<br class=""><br class="">Do you know how changing the return type tipped dialyzer off?<br class=""></blockquote><br class="">That means dialyzer figured out that this code path is never executed successfully, and contains a typing error. It is not a mistake to have a dead code, according to Dialyzer, just having all code dead in a function.<br class=""><br class="">Explicit contract means declaring types for counter_state, though maybe it is ignored for local records.<br class=""><br class="">Changing the return type might’ve broken the exact code path that can change ‘use’ to ‘false’.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I checked, it does not. This is very confusing. I can quite easily call the function with use=false, by changing a setting in riak’s advanced.config. Is the fact that this value comes from an app variable the problem?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>So, it executed correctly with use=false, without errors, and dialyzer still reports it? Then that is a bug. Dialyzer should never report bugs in working code.</div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">30 марта 2017 г., в 10:04, Russell Brown <<a href="mailto:russell@wombat.me" class="">russell@wombat.me</a>> написал(а):<br class=""><br class="">Hi,<br class=""><br class="">I have a dialyzer error I can’t figure out, at all, it’s truly very weird, even for dialyzer.<br class=""><br class="">The error is:<span class="Apple-converted-space"> </span><br class=""><br class="">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()}<br class="">riak_object:object/0<br class=""><br class=""><br class="">The code in question is:<br class=""><br class="">%% @private generate an epoch actor, and update the vnode state.<br class="">-spec new_key_epoch(#state{}) -> {NewEpoch::boolean(), EpochActor :: binary(), #state{}}.<br class="">new_key_epoch(State=#state{vnodeid=VId, counter=#counter_state{use=false}}) -><br class="">{false, VId, State};<br class="">new_key_epoch(State) -><br class="">NewState=#state{counter=#counter_state{cnt=Cntr}, vnodeid=VId} = update_counter(State),<br class="">EpochId = key_epoch_actor(VId, Cntr),<br class="">{true, EpochId, NewState}.<br class=""><br class=""><br class="">What is really freaky (to me) is that this code (the previous version) does not provoke a dialyzer warning:<br class=""><br class="">%% @private generate an epoch actor, and update the vnode state.<br class="">-spec new_key_epoch(#state{}) -> {EpochActor :: binary(), #state{}}.<br class="">new_key_epoch(State=#state{vnodeid=VId, counter=#counter_state{use=false}}) -><br class="">{VId, State};<br class="">new_key_epoch(State) -><br class="">NewState=#state{counter=#counter_state{cnt=Cntr}, vnodeid=VId} = update_counter(State),<br class="">EpochId = key_epoch_actor(VId, Cntr),<br class="">{EpochId, NewState}.<br class=""><br class="">The record definition for #counter_state is:<br class=""><br class="">-record(counter_state, {<br class="">     use = true :: boolean(),<br class="">     cnt = 0 :: non_neg_integer(),<br class="">     lease = 0 :: non_neg_integer(),<br class="">     lease_size = 0 :: non_neg_integer(),<br class="">     leasing = false :: boolean()<br class="">    }).<br class=""><br class="">I have missed out the record definition for #state as it is huge, but crucially, unchanged between the two definitions of new_key_epoch/1 above.<br class=""><br class="">If the match in the function head, and the record, are exactly the same between the two versions of the code, why does the one that returns a three tuple provoke a warning?<br class=""><br class="">Many thanks in advance if you can help<br class=""><br class="">Cheers<br class=""><br class="">Russell<br class=""><br class="">_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions</blockquote></blockquote></blockquote></blockquote></div></blockquote></div><br class=""></body></html>