zf

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

contract_subtype.ex (1458B)


      1 defmodule Dialyxir.Warnings.ContractSubtype do
      2   # TODO: could not create warning with this example (and --overspecs)
      3   @moduledoc """
      4   The type in the @spec does not completely cover the types returned
      5   by function.
      6 
      7   ## Example
      8 
      9       defmodule Example do
     10         @spec ok(:ok | :error) :: :ok
     11         def ok(:ok) do
     12           :ok
     13         end
     14 
     15         def ok(:error) do
     16           :error
     17         end
     18       end
     19   """
     20 
     21   @behaviour Dialyxir.Warning
     22 
     23   @impl Dialyxir.Warning
     24   @spec warning() :: :contract_subtype
     25   def warning(), do: :contract_subtype
     26 
     27   @impl Dialyxir.Warning
     28   @spec format_short([String.t()]) :: String.t()
     29   def format_short([_module, function | _]) do
     30     "Type specification for #{function} is a subtype of the success typing."
     31   end
     32 
     33   @impl Dialyxir.Warning
     34   @spec format_long([String.t()]) :: String.t()
     35   def format_long([module, function, arity, contract, signature]) do
     36     pretty_module = Erlex.pretty_print(module)
     37     pretty_signature = Erlex.pretty_print_contract(signature)
     38     pretty_contract = Erlex.pretty_print_contract(contract, module, function)
     39 
     40     """
     41     Type specification is a subtype of the success typing.
     42 
     43     Function:
     44     #{pretty_module}.#{function}/#{arity}
     45 
     46     Type specification:
     47     @spec #{function}#{pretty_contract}
     48 
     49     Success typing:
     50     @spec #{function}#{pretty_signature}
     51     """
     52   end
     53 
     54   @impl Dialyxir.Warning
     55   @spec explain() :: String.t()
     56   def explain() do
     57     @moduledoc
     58   end
     59 end