Skip to content

Commit

Permalink
Merge pull request #14 from zotonic/cleanup-dict-dialyzer
Browse files Browse the repository at this point in the history
Replace convoluted dict lookup with dialyzer nowarn directive.
  • Loading branch information
mworrell authored Sep 15, 2022
2 parents 13b02d1 + bf1516a commit 4beb553
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
otp_version: [20.3,21,22,23,24]
otp_version: [20.3,21,22,23,24,25]
os: [ubuntu-latest]

container:
Expand All @@ -32,5 +32,5 @@ jobs:
run: make test
- name: XRef
run: make xref
# - name: Dialyzer
# run: make dialyzer
- name: Dialyzer
run: make dialyzer
29 changes: 16 additions & 13 deletions src/depcache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ get_wait(Key, Server) ->
Key :: key(),
Server :: depcache_server(),
Result :: [{pid(), Tag}],
Tag :: atom().
Tag :: gen_server:reply_tag().

get_waiting_pids(Key, Server) ->
gen_server:call(Server, {get_waiting_pids, Key}, ?MAX_GET_WAIT*1000).
Expand Down Expand Up @@ -712,37 +712,37 @@ init(Config) ->

-spec handle_call(Request, From, State) -> Result when
Request :: get_tables,
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Meta_table :: ets:tab(),
Deps_table :: ets:tab(),
Data_table :: ets:tab(),
Result :: {reply, {ok, {Meta_table, Deps_table, Data_table}}, State};
(Request, From, State) -> Result when
Request :: get_wait,
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, Reply, state()} | {noreply, state()},
Reply :: undefined | {ok, term()};
(Request, From, State) -> Result when
Request :: {get_waiting_pids, Key},
Key :: key(),
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, [{pid(), Tag}], state()},
Tag :: atom();
Tag :: gen_server:reply_tag();
(Request, From, State) -> Result when
Request :: {get, Key},
Key :: key(),
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, Reply, State},
Reply :: undefined | {ok, term()};
(Request, From, State) -> Result when
Request :: {get, Key, SubKey},
Key :: key(),
SubKey :: key(),
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, Reply, State},
Reply :: undefined | {ok, term()};
Expand All @@ -752,19 +752,19 @@ init(Config) ->
Data :: any(),
MaxAge :: max_age_secs(),
Depend :: dependencies(),
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, Reply, State},
Reply :: ok;
(Request, From, State) -> Result when
Request :: {flush, Key},
Key :: key(),
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, ok, State};
(Request, From, State) -> Result when
Request :: flush,
From :: {pid(), atom()},
From :: {pid(), gen_server:reply_tag()},
State :: state(),
Result :: {reply, ok, State}.
handle_call(get_tables, _From, State) ->
Expand Down Expand Up @@ -1206,6 +1206,11 @@ check_depend(Serial, Depend, DepsTable) ->
lists:foldl(CheckDepend, true, Depend).


%% Don't warn about types in find_value, especially the dict lookup
%% triggers warnings from dialyzer about the tuple not being an
%% opaque dict() type.
-dialyzer({nowarn_function, find_value/2}).

%% @private
%% @doc Search by value in some set of data.

Expand Down Expand Up @@ -1258,9 +1263,7 @@ find_value(Key, Tuple) when is_tuple(Tuple) ->
Module = element(1, Tuple),
case Module of
dict ->
{Key1, Value} = Tuple,
Dict = dict:append(Key1, Value, dict:new()),
case dict:find(Key, Dict) of
case dict:find(Key, Tuple) of
{ok, Val} ->
Val;
_ ->
Expand Down

0 comments on commit 4beb553

Please sign in to comment.