Skip to content

Commit 1dd034d

Browse files
author
José Valim
committed
Merge pull request #2752 from fishcakez/dialyzer_warns
Fix some dialyzer warnings
2 parents 1ae24c5 + 2417b19 commit 1dd034d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+147
-72
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test_stdlib: compile
183183

184184
#==> Dialyzer tasks
185185

186-
DIALYZER_OPTS = --no_check_plt --fullpath -Werror_handling -Wunmatched_returns -Wrace_conditions -Wunderspecs
186+
DIALYZER_OPTS = --no_check_plt --fullpath -Werror_handling -Wunmatched_returns -Wunderspecs
187187
PLT = .elixir.plt
188188

189189
$(PLT):

lib/elixir/lib/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ defmodule Application do
201201
`:applications` in the `.app` file in case they were not previously
202202
started.
203203
"""
204-
@spec ensure_all_started(app, start_type) :: {:ok, [app]} | {:error, term}
204+
@spec ensure_all_started(app, start_type) :: {:ok, [app]} | {:error, {app, term}}
205205
def ensure_all_started(app, type \\ :temporary) when is_atom(app) do
206206
:application.ensure_all_started(app, type)
207207
end

lib/elixir/lib/file.ex

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ defmodule File do
7575
@type posix :: :file.posix()
7676
@type io_device :: :file.io_device()
7777
@type stat_options :: [time: :local | :universal | :posix]
78+
@type mode :: :append | :binary | :compressed | :delayed_write | :exclusive |
79+
:raw | :read | :read_ahead | :sync | :write |
80+
{:encoding , :latin1 | :unicode | :utf16 | :utf32 | :utf8 |
81+
{:utf16, :big | :little} | {:utf32, :big | :little}} |
82+
{:read_ahead, pos_integer} |
83+
{:delayed_write, non_neg_integer, non_neg_integer}
7884

7985
@doc """
8086
Returns `true` if the path is a regular file.
@@ -612,15 +618,15 @@ defmodule File do
612618
613619
Check `File.open/2` for other available options.
614620
"""
615-
@spec write(Path.t, iodata, list) :: :ok | {:error, posix}
621+
@spec write(Path.t, iodata, [mode]) :: :ok | {:error, posix}
616622
def write(path, content, modes \\ []) do
617623
F.write_file(IO.chardata_to_string(path), content, modes)
618624
end
619625

620626
@doc """
621627
Same as `write/3` but raises an exception if it fails, returns `:ok` otherwise.
622628
"""
623-
@spec write!(Path.t, iodata, list) :: :ok | no_return
629+
@spec write!(Path.t, iodata, [mode]) :: :ok | no_return
624630
def write!(path, content, modes \\ []) do
625631
path = IO.chardata_to_string(path)
626632
case F.write_file(path, content, modes) do
@@ -902,7 +908,8 @@ defmodule File do
902908
File.close(file)
903909
904910
"""
905-
@spec open(Path.t, list) :: {:ok, io_device} | {:error, posix}
911+
@spec open(Path.t, [mode | :ram]) :: {:ok, io_device} | {:error, posix}
912+
@spec open(Path.t, (io_device -> res)) :: {:ok, res} | {:error, posix} when res: var
906913
def open(path, modes \\ [])
907914

908915
def open(path, modes) when is_list(modes) do
@@ -935,7 +942,7 @@ defmodule File do
935942
end)
936943
937944
"""
938-
@spec open(Path.t, list, (io_device -> res)) :: {:ok, res} | {:error, posix} when res: var
945+
@spec open(Path.t, [mode | :ram], (io_device -> res)) :: {:ok, res} | {:error, posix} when res: var
939946
def open(path, modes, function) do
940947
case open(path, modes) do
941948
{:ok, device} ->
@@ -953,7 +960,7 @@ defmodule File do
953960
954961
Returns the `io_device` otherwise.
955962
"""
956-
@spec open!(Path.t, list) :: io_device | no_return
963+
@spec open!(Path.t, [mode]) :: io_device | no_return
957964
def open!(path, modes \\ []) do
958965
path = IO.chardata_to_string(path)
959966
case open(path, modes) do
@@ -968,7 +975,7 @@ defmodule File do
968975
969976
Returns the function result otherwise.
970977
"""
971-
@spec open!(Path.t, list, (io_device -> res)) :: res | no_return when res: var
978+
@spec open!(Path.t, [mode | :ram], (io_device -> res)) :: res | no_return when res: var
972979
def open!(path, modes, function) do
973980
path = IO.chardata_to_string(path)
974981
case open(path, modes, function) do
@@ -1124,15 +1131,15 @@ defmodule File do
11241131
Returns `:ok` on success, or `{:error, reason}`
11251132
on failure.
11261133
"""
1127-
@spec chmod(Path.t, integer) :: :ok | {:error, posix}
1134+
@spec chmod(Path.t, non_neg_integer) :: :ok | {:error, posix}
11281135
def chmod(path, mode) do
11291136
F.change_mode(IO.chardata_to_string(path), mode)
11301137
end
11311138

11321139
@doc """
11331140
Same as `chmod/2`, but raises an exception in case of failure. Otherwise `:ok`.
11341141
"""
1135-
@spec chmod!(Path.t, integer) :: :ok | no_return
1142+
@spec chmod!(Path.t, non_neg_integer) :: :ok | no_return
11361143
def chmod!(path, mode) do
11371144
path = IO.chardata_to_string(path)
11381145
case chmod(path, mode) do
@@ -1147,15 +1154,15 @@ defmodule File do
11471154
for a given `file`. Returns `:ok` on success, or
11481155
`{:error, reason}` on failure.
11491156
"""
1150-
@spec chgrp(Path.t, integer) :: :ok | {:error, posix}
1157+
@spec chgrp(Path.t, non_neg_integer) :: :ok | {:error, posix}
11511158
def chgrp(path, gid) do
11521159
F.change_group(IO.chardata_to_string(path), gid)
11531160
end
11541161

11551162
@doc """
11561163
Same as `chgrp/2`, but raises an exception in case of failure. Otherwise `:ok`.
11571164
"""
1158-
@spec chgrp!(Path.t, integer) :: :ok | no_return
1165+
@spec chgrp!(Path.t, non_neg_integer) :: :ok | no_return
11591166
def chgrp!(path, gid) do
11601167
path = IO.chardata_to_string(path)
11611168
case chgrp(path, gid) do
@@ -1170,15 +1177,15 @@ defmodule File do
11701177
for a given `file`. Returns `:ok` on success,
11711178
or `{:error, reason}` on failure.
11721179
"""
1173-
@spec chown(Path.t, integer) :: :ok | {:error, posix}
1180+
@spec chown(Path.t, non_neg_integer) :: :ok | {:error, posix}
11741181
def chown(path, uid) do
11751182
F.change_owner(IO.chardata_to_string(path), uid)
11761183
end
11771184

11781185
@doc """
11791186
Same as `chown/2`, but raises an exception in case of failure. Otherwise `:ok`.
11801187
"""
1181-
@spec chown!(Path.t, integer) :: :ok | no_return
1188+
@spec chown!(Path.t, non_neg_integer) :: :ok | no_return
11821189
def chown!(path, uid) do
11831190
path = IO.chardata_to_string(path)
11841191
case chown(path, uid) do

lib/elixir/lib/gen_event.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ defmodule GenEvent do
678678

679679
@doc false
680680
def system_replace_state(fun, [name, handlers, hib]) do
681-
{handlers, states} =
681+
[handlers, states] =
682682
List.unzip(for handler <- handlers do
683683
handler(module: mod, id: id, state: state) = handler
684684
cur = {mod, id, state}

lib/elixir/lib/gen_event/stream.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ defimpl Enumerable, for: GenEvent.Stream do
150150
# If we reach this branch, the handler was not removed yet,
151151
# so we trigger a request for doing so.
152152
defp stop(stream, {pid, ref, _} = acc) do
153-
Task.start(fn -> GenEvent.remove_handler(pid, {GenEvent.Stream, ref}, :shutdown) end)
153+
_ = Task.start(fn -> GenEvent.remove_handler(pid, {GenEvent.Stream, ref}, :shutdown) end)
154154
stop(stream, {:removed, acc})
155155
end
156156

lib/elixir/lib/inspect/algebra.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ defmodule Inspect.Algebra do
482482
and returns an IO data representation of the best layout for the
483483
document to fit in the given width.
484484
"""
485-
@spec format(t, non_neg_integer | :infinity) :: binary
485+
@spec format(t, non_neg_integer | :infinity) :: iodata
486486
def format(d, w) do
487487
format(w, 0, [{0, default_mode(w), doc_group(d)}])
488488
end

lib/elixir/lib/integer.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Integer do
111111
"64"
112112
113113
"""
114-
@spec to_string(integer, pos_integer) :: String.t
114+
@spec to_string(integer, 2..36) :: String.t
115115
def to_string(some_integer, base) do
116116
:erlang.integer_to_binary(some_integer, base)
117117
end
@@ -144,7 +144,7 @@ defmodule Integer do
144144
'3FF'
145145
146146
"""
147-
@spec to_char_list(integer, pos_integer) :: char_list
147+
@spec to_char_list(integer, 2..36) :: char_list
148148
def to_char_list(number, base) do
149149
:erlang.integer_to_list(number, base)
150150
end

lib/elixir/lib/kernel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2384,7 +2384,7 @@ defmodule Kernel do
23842384
it is not loaded. Check `Code.ensure_loaded/1` for more
23852385
information.
23862386
"""
2387-
@spec function_exported?(atom | tuple, atom, integer) :: boolean
2387+
@spec function_exported?(atom | tuple, atom, arity) :: boolean
23882388
def function_exported?(module, function, arity) do
23892389
:erlang.function_exported(module, function, arity)
23902390
end

lib/elixir/lib/kernel/cli.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ defmodule Kernel.CLI do
408408
end
409409

410410
defp wrapper(fun) do
411-
fun.()
411+
_ = fun.()
412412
:ok
413413
end
414414

lib/elixir/lib/keyword.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ defmodule Keyword do
136136
:error
137137
138138
"""
139-
@spec fetch(t, key) :: {:ok, value}
139+
@spec fetch(t, key) :: {:ok, value} | :error
140140
def fetch(keywords, key) when is_list(keywords) and is_atom(key) do
141141
case :lists.keyfind(key, 1, keywords) do
142142
{^key, value} -> {:ok, value}

0 commit comments

Comments
 (0)