zf

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

contract_supertype.ex (1316B)


      1 defmodule Dialyxir.Warnings.ContractSupertype do
      2   @moduledoc """
      3   The @spec, while not incorrect, is more general than the type
      4   returned by the function.
      5 
      6   ## Example
      7 
      8       defmodule Example do
      9         @spec ok() :: any
     10         def ok() do
     11           :ok
     12         end
     13       end
     14   """
     15 
     16   @behaviour Dialyxir.Warning
     17 
     18   @impl Dialyxir.Warning
     19   @spec warning() :: :contract_supertype
     20   def warning(), do: :contract_supertype
     21 
     22   @impl Dialyxir.Warning
     23   @spec format_short([String.t()]) :: String.t()
     24   def format_short([_module, function | _]) do
     25     "Type specification for #{function} is a supertype of the success typing."
     26   end
     27 
     28   @impl Dialyxir.Warning
     29   @spec format_long([String.t()]) :: String.t()
     30   def format_long([module, function, arity, contract, signature]) do
     31     pretty_module = Erlex.pretty_print(module)
     32     pretty_contract = Erlex.pretty_print_contract(contract)
     33     pretty_signature = Erlex.pretty_print_contract(signature)
     34 
     35     """
     36     Type specification is a supertype of the success typing.
     37 
     38     Function:
     39     #{pretty_module}.#{function}/#{arity}
     40 
     41     Type specification:
     42     @spec #{function}#{pretty_contract}
     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