Skip to content

Commit b5885a6

Browse files
Add guards to functions in Application module (#14687)
1 parent 2a71415 commit b5885a6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/elixir/lib/application.ex

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ defmodule Application do
507507
of all loaded applications. Returns `nil` if
508508
the module is not listed in any application spec.
509509
"""
510-
@spec get_application(atom) :: atom | nil
510+
@spec get_application(module) :: app | nil
511511
def get_application(module) when is_atom(module) do
512512
case :application.get_application(module) do
513513
{:ok, app} -> app
@@ -814,7 +814,7 @@ defmodule Application do
814814
stick after the application is loaded and also on application reload.
815815
"""
816816
@spec put_env(app, key, value, timeout: timeout, persistent: boolean) :: :ok
817-
def put_env(app, key, value, opts \\ []) when is_atom(app) do
817+
def put_env(app, key, value, opts \\ []) when is_atom(app) and is_list(opts) do
818818
maybe_warn_on_app_env_key(app, key)
819819
:application.set_env(app, key, value, opts)
820820
end
@@ -856,7 +856,7 @@ defmodule Application do
856856
It receives the same options as `put_env/4`. Returns `:ok`.
857857
"""
858858
@spec delete_env(app, key, timeout: timeout, persistent: boolean) :: :ok
859-
def delete_env(app, key, opts \\ []) when is_atom(app) do
859+
def delete_env(app, key, opts \\ []) when is_atom(app) and is_list(opts) do
860860
maybe_warn_on_app_env_key(app, key)
861861
:application.unset_env(app, key, opts)
862862
end
@@ -921,11 +921,11 @@ defmodule Application do
921921
{:ok, [app]} | {:error, term}
922922
def ensure_all_started(app_or_apps, type_or_opts \\ [])
923923

924-
def ensure_all_started(app, type) when is_atom(type) do
925-
ensure_all_started(app, type: type)
924+
def ensure_all_started(app_or_apps, type) when is_atom(type) do
925+
ensure_all_started(app_or_apps, type: type)
926926
end
927927

928-
def ensure_all_started(app, opts) when is_atom(app) do
928+
def ensure_all_started(app, opts) when is_atom(app) and is_list(opts) do
929929
ensure_all_started([app], opts)
930930
end
931931

@@ -1056,7 +1056,8 @@ defmodule Application do
10561056
Returns a list with information about the applications which are currently running.
10571057
"""
10581058
@spec started_applications(timeout) :: [{app, description :: charlist(), vsn :: charlist()}]
1059-
def started_applications(timeout \\ 5000) do
1059+
def started_applications(timeout \\ 5000)
1060+
when timeout == :infinity or (is_integer(timeout) and timeout >= 0) do
10601061
:application.which_applications(timeout)
10611062
end
10621063

0 commit comments

Comments
 (0)