zf

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

call_with_opaque.ex (1603B)


      1 defmodule Dialyxir.Warnings.CallWithOpaque do
      2   @behaviour Dialyxir.Warning
      3 
      4   @impl Dialyxir.Warning
      5   @spec warning() :: :call_with_opaque
      6   def warning(), do: :call_with_opaque
      7 
      8   @impl Dialyxir.Warning
      9   @spec format_short([String.t()]) :: String.t()
     10   def format_short([_module, function | _]) do
     11     "Type mismatch in call with opaque term in #{function}."
     12   end
     13 
     14   @impl Dialyxir.Warning
     15   @spec format_long([String.t()]) :: String.t()
     16   def format_long([module, function, args, arg_positions, expected_args]) do
     17     pretty_module = Erlex.pretty_print(module)
     18 
     19     "The call #{pretty_module}.#{function}#{args} contains #{form_positions(arg_positions)} " <>
     20       "when #{form_expected(expected_args)}}."
     21   end
     22 
     23   defp form_positions(arg_positions = [_]) do
     24     form_position_string = Dialyxir.WarningHelpers.form_position_string(arg_positions)
     25     "an opaque term in #{form_position_string} argument"
     26   end
     27 
     28   defp form_positions(arg_positions) do
     29     form_position_string = Dialyxir.WarningHelpers.form_position_string(arg_positions)
     30     "opaque terms in #{form_position_string} arguments"
     31   end
     32 
     33   defp form_expected([type]) do
     34     type_string = :erl_types.t_to_string(type)
     35 
     36     if :erl_types.t_is_opaque(type) do
     37       "an opaque term of type #{type_string} is expected"
     38     else
     39       "a structured term of type #{type_string} is expected"
     40     end
     41   end
     42 
     43   defp form_expected(_expected_args) do
     44     "terms of different types are expected in these positions"
     45   end
     46 
     47   @impl Dialyxir.Warning
     48   @spec explain() :: String.t()
     49   def explain() do
     50     Dialyxir.Warning.default_explain()
     51   end
     52 end