zf

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

pattern_match.ex (1148B)


      1 defmodule Dialyxir.Warnings.PatternMatch do
      2   @moduledoc """
      3   The pattern matching is never given a value that satisfies all of
      4   its clauses.
      5 
      6   ## Example
      7 
      8       defmodule Example do
      9         def ok() do
     10           unmatched(:ok)
     11         end
     12 
     13         defp unmatched(:ok), do: :ok
     14 
     15         defp unmatched(:error), do: :error
     16       end
     17   """
     18 
     19   @behaviour Dialyxir.Warning
     20 
     21   @impl Dialyxir.Warning
     22   @spec warning() :: :pattern_match
     23   def warning(), do: :pattern_match
     24 
     25   @impl Dialyxir.Warning
     26   @spec format_short([String.t()]) :: String.t()
     27   def format_short([_pattern, type]) do
     28     pretty_type = Erlex.pretty_print_type(type)
     29     "The pattern can never match the type #{pretty_type}."
     30   end
     31 
     32   @impl Dialyxir.Warning
     33   @spec format_long([String.t()]) :: String.t()
     34   def format_long([pattern, type]) do
     35     pretty_pattern = Erlex.pretty_print_pattern(pattern)
     36     pretty_type = Erlex.pretty_print_type(type)
     37 
     38     """
     39     The pattern can never match the type.
     40 
     41     Pattern:
     42     #{pretty_pattern}
     43 
     44     Type:
     45     #{pretty_type}
     46     """
     47   end
     48 
     49   @impl Dialyxir.Warning
     50   @spec explain() :: String.t()
     51   def explain() do
     52     @moduledoc
     53   end
     54 end