guard_fail_pattern.ex (1045B)
1 defmodule Dialyxir.Warnings.GuardFailPattern do 2 @moduledoc """ 3 The clause guard describes a condition of literals that fails the pattern 4 given in the function head. 5 6 ## Example 7 8 defmodule Example do 9 def ok(n = 0) when not n < 1 do 10 :ok 11 end 12 end 13 """ 14 15 @behaviour Dialyxir.Warning 16 17 @impl Dialyxir.Warning 18 @spec warning() :: :guard_fail_pat 19 def warning(), do: :guard_fail_pat 20 21 @impl Dialyxir.Warning 22 @spec format_short([String.t()]) :: String.t() 23 def format_short([pattern, _]) do 24 "The clause guard #{pattern} cannot succeed." 25 end 26 27 @impl Dialyxir.Warning 28 @spec format_long([String.t()]) :: String.t() 29 def format_long([pattern, type]) do 30 pretty_type = Erlex.pretty_print_type(type) 31 pretty_pattern = Erlex.pretty_print_pattern(pattern) 32 33 "The clause guard cannot succeed. The pattern #{pretty_pattern} " <> 34 "was matched against the type #{pretty_type}." 35 end 36 37 @impl Dialyxir.Warning 38 @spec explain() :: String.t() 39 def explain() do 40 @moduledoc 41 end 42 end