zf

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

callback_argument_type_mismatch.ex (1552B)


      1 defmodule Dialyxir.Warnings.CallbackArgumentTypeMismatch do
      2   @moduledoc """
      3   Type of argument does not match the callback's expected type.
      4 
      5   ## Example
      6 
      7       defmodule ExampleBehaviour do
      8         @callback ok(:ok) :: :ok
      9       end
     10 
     11       defmodule Example do
     12 
     13         @behaviour ExampleBehaviour
     14 
     15         def ok(:error) do
     16           :ok
     17         end
     18     end
     19   """
     20   @behaviour Dialyxir.Warning
     21 
     22   @impl Dialyxir.Warning
     23   @spec warning() :: :callback_arg_type_mismatch
     24   def warning(), do: :callback_arg_type_mismatch
     25 
     26   @impl Dialyxir.Warning
     27   @spec format_short([String.t()]) :: String.t()
     28   def format_short([_behaviour, function, arity | _]) do
     29     "Type mismatch with behaviour callback to #{function}/#{arity}."
     30   end
     31 
     32   @impl Dialyxir.Warning
     33   @spec format_long([String.t()]) :: String.t()
     34   def format_long([behaviour, function, arity, position, success_type, callback_type]) do
     35     pretty_behaviour = Erlex.pretty_print(behaviour)
     36     pretty_success_type = Erlex.pretty_print_type(success_type)
     37     pretty_callback_type = Erlex.pretty_print_type(callback_type)
     38     ordinal_position = Dialyxir.WarningHelpers.ordinal(position)
     39 
     40     """
     41     The inferred type for the #{ordinal_position} argument is not a
     42     supertype of the expected type for the #{function}/#{arity} callback
     43     in the #{pretty_behaviour} behaviour.
     44 
     45     Success type:
     46     #{pretty_success_type}
     47 
     48     Behaviour callback type:
     49     #{pretty_callback_type}
     50     """
     51   end
     52 
     53   @impl Dialyxir.Warning
     54   @spec explain() :: String.t()
     55   def explain() do
     56     @moduledoc
     57   end
     58 end