zf

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

invalid_contract.ex (1334B)


      1 defmodule Dialyxir.Warnings.InvalidContract do
      2   @moduledoc """
      3   The @spec for the function does not match the success typing of the
      4   function.
      5 
      6   ## Example
      7 
      8       defmodule Example do
      9         @spec process(:error) :: :ok
     10         def process(:ok) do
     11           :ok
     12         end
     13       end
     14 
     15   The @spec in this case claims that the function accepts a parameter
     16   :error but the function head only accepts :ok, resulting in the
     17   mismatch.
     18   """
     19 
     20   @behaviour Dialyxir.Warning
     21 
     22   @impl Dialyxir.Warning
     23   @spec warning() :: :invalid_contract
     24   def warning(), do: :invalid_contract
     25 
     26   @impl Dialyxir.Warning
     27   @spec format_short([String.t()]) :: String.t()
     28   def format_short([_module, function | _]) do
     29     "Invalid type specification for function #{function}."
     30   end
     31 
     32   @impl Dialyxir.Warning
     33   @spec format_long([String.t()]) :: String.t()
     34   def format_long([module, function, arity, signature]) do
     35     pretty_module = Erlex.pretty_print(module)
     36     pretty_signature = Erlex.pretty_print_contract(signature)
     37 
     38     """
     39     The @spec for the function does not match the success typing of the function.
     40 
     41     Function:
     42     #{pretty_module}.#{function}/#{arity}
     43 
     44     Success typing:
     45     @spec #{function}#{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