no_return.ex (1731B)
1 defmodule Dialyxir.Warnings.NoReturn do 2 @moduledoc """ 3 The function has no return. This is usually due to an issue later on 4 in the call stack causing it to not be recognized as returning for 5 some reason. It is often helpful to cross reference the complete 6 list of warnings with the call stack in the function and fix the 7 deepest part of the call stack, which will usually fix many of the 8 other no_return errors. 9 10 ## Example 11 12 defmodule Example do 13 def ok() do 14 Enum.each([1, 2, 3], fn _ -> raise "error" end) 15 end 16 end 17 18 or 19 20 defmodule Example do 21 def ok() do 22 raise "error" 23 24 :ok 25 end 26 27 def ok(:ok) do 28 ok() 29 end 30 end 31 """ 32 33 @behaviour Dialyxir.Warning 34 35 @impl Dialyxir.Warning 36 @spec warning() :: :no_return 37 def warning(), do: :no_return 38 39 @impl Dialyxir.Warning 40 @spec format_short([String.t()]) :: String.t() 41 def format_short(args), do: format_long(args) 42 43 @impl Dialyxir.Warning 44 @spec format_long([String.t() | atom]) :: String.t() 45 def format_long([type | name]) do 46 name_string = 47 case name do 48 [] -> 49 "The created anonymous function" 50 51 [function, arity] -> 52 "Function #{function}/#{arity}" 53 end 54 55 type_string = 56 case type do 57 :no_match -> 58 "has no clauses that will ever match." 59 60 :only_explicit -> 61 "only terminates with explicit exception." 62 63 :only_normal -> 64 "has no local return." 65 66 :both -> 67 "has no local return." 68 end 69 70 "#{name_string} #{type_string}" 71 end 72 73 @impl Dialyxir.Warning 74 @spec explain() :: String.t() 75 def explain() do 76 @moduledoc 77 end 78 end