/
pattern_match.ex
54 lines (42 loc) · 1.12 KB
/
pattern_match.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
defmodule Dialyxir.Warnings.PatternMatch do
@moduledoc """
The pattern matching is never given a value that satisfies all of
its clauses.
## Example
defmodule Example do
def ok() do
unmatched(:ok)
end
defp unmatched(:ok), do: :ok
defp unmatched(:error), do: :error
end
"""
@behaviour Dialyxir.Warning
@impl Dialyxir.Warning
@spec warning() :: :pattern_match
def warning(), do: :pattern_match
@impl Dialyxir.Warning
@spec format_short([String.t()]) :: String.t()
def format_short([_pattern, type]) do
pretty_type = Erlex.pretty_print_type(type)
"The pattern can never match the type #{pretty_type}."
end
@impl Dialyxir.Warning
@spec format_long([String.t()]) :: String.t()
def format_long([pattern, type]) do
pretty_pattern = Erlex.pretty_print_pattern(pattern)
pretty_type = Erlex.pretty_print_type(type)
"""
The pattern can never match the type.
Pattern:
#{pretty_pattern}
Type:
#{pretty_type}
"""
end
@impl Dialyxir.Warning
@spec explain() :: String.t()
def explain() do
@moduledoc
end
end