-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
negative_guard_fail.ex
68 lines (53 loc) · 1.29 KB
/
negative_guard_fail.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
defmodule Dialyxir.Warnings.NegativeGuardFail do
@moduledoc """
The function guard either presents an impossible guard or the only
calls will never succeed against the guards.
## Example
defmodule Example do
def ok(ok = "ok") when not is_bitstring(ok) do
:ok
end
end
or
defmodule Example do
def ok() do
ok(:ok)
end
defp ok(ok) when not is_atom(ok) do
:ok
end
end
"""
@behaviour Dialyxir.Warning
@impl Dialyxir.Warning
@spec warning() :: :neg_guard_fail
def warning(), do: :neg_guard_fail
@impl Dialyxir.Warning
@spec format_short([String.t()]) :: String.t()
def format_short(_) do
"The guard test can never succeed."
end
@impl Dialyxir.Warning
@spec format_long([String.t()]) :: String.t()
def format_long([guard, args]) do
pretty_args = Erlex.pretty_print_args(args)
"""
Guard test:
not #{guard}#{pretty_args}
can never succeed.
"""
end
def format_long([arg1, infix, arg2]) do
pretty_infix = Erlex.pretty_print_infix(infix)
"""
Guard test:
not #{arg1} #{pretty_infix} #{arg2}
can never succeed.
"""
end
@impl Dialyxir.Warning
@spec explain() :: String.t()
def explain() do
@moduledoc
end
end