call.ex (1353B)
1 defmodule Dialyxir.Warnings.Call do 2 @moduledoc """ 3 The function call will not succeed. 4 5 ## Example 6 7 defmodule Example do 8 def ok() do 9 ok(:error) 10 end 11 12 def ok(:ok) do 13 :ok 14 end 15 end 16 """ 17 18 @behaviour Dialyxir.Warning 19 20 @impl Dialyxir.Warning 21 @spec warning() :: :call 22 def warning(), do: :call 23 24 @impl Dialyxir.Warning 25 @spec format_short([String.t()]) :: String.t() 26 def format_short([_module, function | _]) do 27 "The function call #{function} will not succeed." 28 end 29 30 @impl Dialyxir.Warning 31 @spec format_long([String.t()]) :: String.t() 32 def format_long([ 33 module, 34 function, 35 args, 36 arg_positions, 37 fail_reason, 38 signature_args, 39 signature_return, 40 contract 41 ]) do 42 pretty_args = Erlex.pretty_print_args(args) 43 pretty_module = Erlex.pretty_print(module) 44 45 call_string = 46 Dialyxir.WarningHelpers.call_or_apply_to_string( 47 arg_positions, 48 fail_reason, 49 signature_args, 50 signature_return, 51 contract 52 ) 53 54 """ 55 The function call will not succeed. 56 57 #{pretty_module}.#{function}#{pretty_args} 58 59 #{String.trim_trailing(call_string)} 60 """ 61 end 62 63 @impl Dialyxir.Warning 64 @spec explain() :: String.t() 65 def explain() do 66 @moduledoc 67 end 68 end