zf

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

extra_range.ex (1265B)


      1 defmodule Dialyxir.Warnings.ExtraRange do
      2   @moduledoc """
      3   The @spec says the function returns more types than the function
      4   actually returns.
      5 
      6   ## Example
      7 
      8       defmodule Example do
      9         @spec ok() :: :ok | :error
     10         def ok() do
     11           :ok
     12         end
     13       end
     14   """
     15 
     16   @behaviour Dialyxir.Warning
     17 
     18   @impl Dialyxir.Warning
     19   @spec warning() :: :extra_range
     20   def warning(), do: :extra_range
     21 
     22   @impl Dialyxir.Warning
     23   @spec format_short([String.t()]) :: String.t()
     24   def format_short([_module, function | _]) do
     25     "@spec for #{function} has more types than are returned by the function."
     26   end
     27 
     28   @impl Dialyxir.Warning
     29   @spec format_long([String.t()]) :: String.t()
     30   def format_long([module, function, arity, extra_ranges, signature_range]) do
     31     pretty_module = Erlex.pretty_print(module)
     32     pretty_extra = Erlex.pretty_print_type(extra_ranges)
     33     pretty_signature = Erlex.pretty_print_type(signature_range)
     34 
     35     """
     36     The type specification has too many types for the function.
     37 
     38     Function:
     39     #{pretty_module}.#{function}/#{arity}
     40 
     41     Extra type:
     42     #{pretty_extra}
     43 
     44     Success typing:
     45     #{pretty_signature}
     46     """
     47   end
     48 
     49   @impl Dialyxir.Warning
     50   @spec explain() :: String.t()
     51   def explain() do
     52     @moduledoc
     53   end
     54 end