zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

guard_fail.ex (1453B)


      1 defmodule Dialyxir.Warnings.GuardFail do
      2   @moduledoc """
      3   The function guard either presents an impossible guard or the only
      4   calls will never succeed against the guards.
      5 
      6   ## Example
      7 
      8       defmodule Example do
      9         def ok() do
     10           ok(0)
     11         end
     12 
     13         defp ok(n) when n > 1 do
     14           :ok
     15         end
     16       end
     17 
     18     or
     19 
     20       defmodule Example do
     21         def ok() when 0 > 1 do
     22           :ok
     23         end
     24       end
     25   """
     26 
     27   @behaviour Dialyxir.Warning
     28 
     29   @impl Dialyxir.Warning
     30   @spec warning() :: :guard_fail
     31   def warning(), do: :guard_fail
     32 
     33   @impl Dialyxir.Warning
     34   @spec format_short([String.t()]) :: String.t()
     35   def format_short(_) do
     36     "The guard clause can never succeed."
     37   end
     38 
     39   @impl Dialyxir.Warning
     40   @spec format_long([String.t()]) :: String.t()
     41   def format_long([]) do
     42     "The guard clause can never succeed."
     43   end
     44 
     45   def format_long([guard, args]) do
     46     pretty_args = Erlex.pretty_print_args(args)
     47 
     48     """
     49     The guard test:
     50 
     51     #{guard}#{pretty_args}
     52 
     53     can never succeed.
     54     """
     55   end
     56 
     57   def format_long([arg, infix, guard]) do
     58     pretty_arg = Erlex.pretty_print_args(arg)
     59     pretty_infix = Erlex.pretty_print_infix(infix)
     60     pretty_guard = Erlex.pretty_print(guard)
     61 
     62     """
     63     The guard clause:
     64 
     65     when #{pretty_arg} #{pretty_infix} #{pretty_guard}
     66 
     67     can never succeed.
     68     """
     69   end
     70 
     71   @impl Dialyxir.Warning
     72   @spec explain() :: String.t()
     73   def explain() do
     74     @moduledoc
     75   end
     76 end