From 6fde1748b9c7a67db1dbd1fb051d630c79656b3a Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 8 Aug 2015 14:17:03 -0500 Subject: fix dialyzer warnings, except 'no local return' warnings --- src/rebar_agent.erl | 2 +- src/rebar_app_discover.erl | 15 +++++---------- src/rebar_core.erl | 4 ++-- src/rebar_prv_deps.erl | 2 +- src/rebar_prv_install_deps.erl | 32 +++++++++----------------------- src/rebar_prv_packages.erl | 10 +++------- src/rebar_prv_shell.erl | 2 +- src/rebar_prv_update.erl | 5 +++++ src/rebar_prv_xref.erl | 2 +- src/rebar_state.erl | 11 +++++++---- src/rebar_utils.erl | 2 +- 11 files changed, 36 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/rebar_agent.erl b/src/rebar_agent.erl index dc45dcf..2b69812 100644 --- a/src/rebar_agent.erl +++ b/src/rebar_agent.erl @@ -104,7 +104,7 @@ refresh_paths(RState) -> ok; {ok, _} -> ?DEBUG("reloading ~p from ~s", [Modules, Path]), - code:replace_path(Name, Path), + code:replace_path(App, Path), [begin code:purge(M), code:delete(M), code:load_file(M) end || M <- Modules] end diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index c5a79a6..3b34539 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -138,7 +138,7 @@ find_app(AppDir, Validate) -> app_dir(AppFile) -> filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))). --spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | {error, term()}. +-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t(). create_app_info(AppDir, AppFile) -> [{application, AppName, AppDetails}] = rebar_config:consult_app_file(AppFile), AppVsn = proplists:get_value(vsn, AppDetails), @@ -208,16 +208,11 @@ try_handle_app_src_file(_, _AppDir, _AppSrcFile, valid) -> try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid ; Validate =:= all -> AppInfo = create_app_info(AppDir, File), - case AppInfo of - {error, Reason} -> - throw({error, {invalid_app_file, File, Reason}}); + case filename:extension(File) of + ".script" -> + {true, rebar_app_info:app_file_src_script(AppInfo, File)}; _ -> - case filename:extension(File) of - ".script" -> - {true, rebar_app_info:app_file_src_script(AppInfo, File)}; - _ -> - {true, rebar_app_info:app_file_src(AppInfo, File)} - end + {true, rebar_app_info:app_file_src(AppInfo, File)} end; try_handle_app_src_file(_, _AppDir, Other, _Validate) -> throw({error, {multiple_app_files, Other}}). diff --git a/src/rebar_core.erl b/src/rebar_core.erl index f097429..ba82a59 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -61,7 +61,7 @@ process_namespace(State, Command) -> {ok, rebar_state:namespace(State, default), Command} end. --spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}. +-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()} | {error, {module(), any()}}. process_command(State, Command) -> %% ? rebar_prv_install_deps:setup_env(State), Providers = rebar_state:providers(State), @@ -103,7 +103,7 @@ process_command(State, Command) -> end end. --spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +-spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()} | {error, {module(), any()}}. do([], State) -> {ok, State}; do([ProviderName | Rest], State) -> diff --git a/src/rebar_prv_deps.erl b/src/rebar_prv_deps.erl index dc356a8..9dc5346 100644 --- a/src/rebar_prv_deps.erl +++ b/src/rebar_prv_deps.erl @@ -33,7 +33,7 @@ do(State) -> true -> {_Packages, Graph} = rebar_state:packages(State), List = merge_deps_per_profile(State), - {_SrcDeps, PkgDeps} = rebar_prv_install_deps:parse_deps("", List, State, [], 0), + {_SrcDeps, PkgDeps} = rebar_prv_install_deps:parse_deps(<<"">>, List, State, [], 0), rebar_digraph:print_solution(Graph, PkgDeps), {ok, State}; false -> diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index b590d03..72350d6 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -289,7 +289,7 @@ package_to_app(DepsDir, Packages, {Name, Vsn, Level}, IsLock, State) -> rebar_app_info:state(AppInfo1, AppState1) end. --spec update_src_deps(atom(), non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary()), list()) -> {rebar_state:t(), list(), list(), sets:set(binary())}. +-spec update_src_deps(atom(), non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary()), list()) -> {list(), list(), list(), rebar_state:t(), sets:set(binary()), list()}. update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Upgrade, Seen, Locks) -> lists:foldl( fun(AppInfo, {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc, LocksAcc}) -> @@ -371,7 +371,7 @@ handle_dep(AppInfo, Profile, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) -> ,NewLocks}. -spec handle_dep(rebar_state:t(), atom(), file:filename_all(), rebar_app_info:t(), list(), integer()) -> - {rebar_app_info:t(), [rebar_app_info:t()], [pkg_dep()], [integer()]}. + {rebar_app_info:t(), [rebar_app_info:t()], [pkg_dep()], [integer()], rebar_state:t()}. handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> Profiles = rebar_state:current_profiles(State), Name = rebar_app_info:name(AppInfo), @@ -413,13 +413,9 @@ maybe_fetch(AppInfo, Profile, Upgrade, Seen, State) -> false -> case rebar_app_discover:find_app(AppDir, all) of false -> - case fetch_app(AppInfo, AppDir, State) of - true -> - maybe_symlink_default(State, Profile, AppDir, AppInfo), - {true, update_app_info(AppDir, AppInfo)}; - Other -> - {Other, AppInfo} - end; + true = fetch_app(AppInfo, AppDir, State), + maybe_symlink_default(State, Profile, AppDir, AppInfo), + {true, update_app_info(AppDir, AppInfo)}; {true, AppInfo1} -> %% Preserve the state we created with overrides AppState = rebar_app_info:state(AppInfo), @@ -477,7 +473,7 @@ make_relative_to_root(State, Path) when is_list(Path) -> Root = rebar_dir:root_dir(State), rebar_dir:make_relative_path(Path, Root). --spec parse_deps(binary(), list(), rebar_state:t(), list(), integer()) -> {[rebar_app_info:t()], [pkg_dep()]}. +-spec parse_deps(binary(), list(), rebar_state:t(), list(), integer()) -> {[rebar_app_info:t()], [tuple()]}. parse_deps(DepsDir, Deps, State, Locks, Level) -> lists:foldl(fun(Dep, Acc) -> Name = case Dep of @@ -575,12 +571,7 @@ new_dep(DepsDir, Name, Vsn, Source, IsLock, State) -> fetch_app(AppInfo, AppDir, State) -> ?INFO("Fetching ~s (~p)", [rebar_app_info:name(AppInfo), rebar_app_info:source(AppInfo)]), Source = rebar_app_info:source(AppInfo), - case rebar_fetch:download_source(AppDir, Source, State) of - true -> - true; - Error -> - throw(Error) - end. + true = rebar_fetch:download_source(AppDir, Source, State). %% This is called after the dep has been downloaded and unpacked, if it hadn't been already. %% So this is the first time for newly downloaded apps that its .app/.app.src data can @@ -602,12 +593,7 @@ maybe_upgrade(AppInfo, AppDir, Upgrade, State) -> case rebar_fetch:needs_update(AppDir, Source, State) of true -> ?INFO("Upgrading ~s", [rebar_app_info:name(AppInfo)]), - case rebar_fetch:download_source(AppDir, Source, State) of - true -> - true; - Error -> - throw(Error) - end; + true = rebar_fetch:download_source(AppDir, Source, State); false -> case Upgrade of true -> @@ -621,7 +607,7 @@ maybe_upgrade(AppInfo, AppDir, Upgrade, State) -> false end. --spec parse_goal(binary(), binary()) -> pkg_dep(). +-spec parse_goal(binary(), binary()) -> {binary(), binary()} | {binary(), binary(), binary()}. parse_goal(Name, Constraint) -> case re:run(Constraint, "([^\\d]*)(\\d.*)", [{capture, [1,2], binary}]) of {match, [<<>>, Vsn]} -> diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl index 9a40734..880d4a6 100644 --- a/src/rebar_prv_packages.erl +++ b/src/rebar_prv_packages.erl @@ -27,13 +27,9 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - case rebar_packages:get_packages(State) of - {Dict, _} -> - print_packages(Dict), - {ok, State}; - error -> - ?PRV_ERROR(load_registry_fail) - end. + {Dict, _} = rebar_packages:get_packages(State), + print_packages(Dict), + {ok, State}. -spec format_error(any()) -> iolist(). format_error(load_registry_fail) -> diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index 431b3e2..d965e1d 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -274,7 +274,7 @@ find_config_relx(State) -> consult_config(State, Filename) end. --spec consult_config(rebar_state:t(), string()) -> {ok, [tuple()]}|{error, tuple()}. +-spec consult_config(rebar_state:t(), string()) -> [tuple()]. consult_config(State, Filename) -> Fullpath = filename:join(rebar_dir:root_dir(State), Filename), ?DEBUG("Loading configuration from ~p", [Fullpath]), diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 64fe65e..50ae2a0 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -15,6 +15,10 @@ -define(PROVIDER, update). -define(DEPS, []). +%% Ignore warning of digraph opqaque type when running dialyzer +-dialyzer({no_opaque, do/1}). +-dialyzer({no_opaque, write_registry/3}). + %% =================================================================== %% Public API %% =================================================================== @@ -63,6 +67,7 @@ do(State) -> format_error(package_index_write) -> "Failed to write package index.". +-spec write_registry(rebar_dict(), {digraph, ets:tid(), ets:tid(), ets:tid(), any()}, rebar_state:t()) -> ok | {error, atom()}. write_registry(Dict, {digraph, Edges, Vertices, Neighbors, _}, State) -> RegistryDir = rebar_packages:package_dir(State), filelib:ensure_dir(filename:join(RegistryDir, "dummy")), diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index 623e946..f600273 100644 --- a/src/rebar_prv_xref.erl +++ b/src/rebar_prv_xref.erl @@ -88,7 +88,7 @@ desc() -> " - (\"mod\":\".*foo\"/\"4\"))",[]}]} ]). --spec prepare(rebar_state:t()) -> {[file:filename()], [atom()]}. +-spec prepare(rebar_state:t()) -> [atom()]. prepare(State) -> {ok, _} = xref:start(xref), ok = xref:set_library_path(xref, code_path(State)), diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 8c43496..59a9588 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -171,7 +171,7 @@ default(State, Opts) -> format_error({profile_not_list, Profile, Other}) -> io_lib:format("Profile config must be a list but for profile '~p' config given as:~n~p", [Profile, Other]). --spec has_all_artifacts(rebar_app_info:t()) -> true | providers:error(). +-spec has_all_artifacts(#state_t{}) -> true | {false, file:filename()}. has_all_artifacts(State) -> Artifacts = rebar_state:get(State, artifacts, []), Dir = rebar_dir:base_dir(State), @@ -188,6 +188,7 @@ all(Dir, [File|Artifacts]) -> all(Dir, Artifacts) end. +-spec code_paths(#state_t{}, atom()) -> [file:filename()]. code_paths(#state_t{code_paths=CodePaths}, Key) -> case dict:find(Key, CodePaths) of {ok, CodePath} -> @@ -196,9 +197,11 @@ code_paths(#state_t{code_paths=CodePaths}, Key) -> [] end. +-spec code_paths(#state_t{}, atom(), [file:filename()]) -> #state_t{}. code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> State#state_t{code_paths=dict:store(Key, CodePath, CodePaths)}. +-spec update_code_paths(#state_t{}, atom(), [file:filename()]) -> #state_t{}. update_code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> case dict:is_key(Key, CodePaths) of true -> @@ -451,15 +454,15 @@ registry(#state_t{registry=Registry}) -> registry(State, Registry) -> State#state_t{registry=Registry}. --spec resources(t()) -> rebar_resource:resource(). +-spec resources(t()) -> [{rebar_resource:type(), module()}]. resources(#state_t{resources=Resources}) -> Resources. --spec resources(t(), [rebar_resource:resource()]) -> t(). +-spec resources(t(), [{rebar_resource:type(), module()}]) -> t(). resources(State, NewResources) -> State#state_t{resources=NewResources}. --spec add_resource(t(), rebar_resource:resource()) -> t(). +-spec add_resource(t(), {rebar_resource:type(), module()}) -> t(). add_resource(State=#state_t{resources=Resources}, Resource) -> State#state_t{resources=[Resource | Resources]}. diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index c7128fc..a61ae37 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -683,7 +683,7 @@ update_code(Paths) -> code:add_patha(Path), ok; {ok, Modules} -> - code:replace_path(Name, Path), + code:replace_path(App, Path), [begin code:purge(M), code:delete(M) end || M <- Modules] end end, Paths). -- cgit v1.1 From ecf6ad552444fa4e786bcd3959079033aff2ab7b Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 8 Aug 2015 14:45:36 -0500 Subject: fix no_return warnings --- src/rebar3.erl | 1 + src/rebar_api.erl | 2 ++ src/rebar_prv_update.erl | 7 ++++++- src/rebar_utils.erl | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar3.erl b/src/rebar3.erl index 46082f0..8004443 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -43,6 +43,7 @@ %% ==================================================================== %% escript Entry point +-spec main(list()) -> no_return(). main(Args) -> try run(Args) of {ok, _State} -> diff --git a/src/rebar_api.erl b/src/rebar_api.erl index ec9f85e..6ebc500 100644 --- a/src/rebar_api.erl +++ b/src/rebar_api.erl @@ -21,10 +21,12 @@ %%%%%%%%%%%%%%%%%%%%%%% %% @doc Interrupts program flow +-spec abort() -> no_return(). abort() -> ?FAIL. %% @doc like {@link error/2}, except it also raises an %% exception to interrupt program flow. +-spec abort(string(), list()) -> no_return(). abort(Str, Args) -> ?ABORT(Str, Args). %% @doc Prints to the console, including a newline diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index 50ae2a0..049e78c 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -15,10 +15,15 @@ -define(PROVIDER, update). -define(DEPS, []). -%% Ignore warning of digraph opqaque type when running dialyzer +%% Ignore warning of digraph opaque type when running dialyzer -dialyzer({no_opaque, do/1}). -dialyzer({no_opaque, write_registry/3}). +%% Ignoring the opaque type warning won't stop dialyzer from warning of +%% no return for functions that had the opaque type warnings +-dialyzer({no_return, do/1}). +-dialyzer({no_return, write_registry/3}). + %% =================================================================== %% Public API %% =================================================================== diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index a61ae37..02a2262 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -510,6 +510,7 @@ log_msg_and_abort(Message) -> ?ABORT(Message, []) end. +-spec debug_log_msg_and_abort(string()) -> err_handler(). debug_log_msg_and_abort(Message) -> fun(Command, {Rc, Output}) -> ?DEBUG("sh(~s)~n" -- cgit v1.1