warning_helpers.ex (2107B)
1 defmodule Dialyxir.WarningHelpers do 2 @spec ordinal(non_neg_integer) :: String.t() 3 def ordinal(1), do: "1st" 4 def ordinal(2), do: "2nd" 5 def ordinal(3), do: "3rd" 6 def ordinal(n) when is_integer(n), do: "#{n}th" 7 8 def call_or_apply_to_string( 9 arg_positions, 10 :only_sig, 11 signature_args, 12 _signature_return, 13 {_overloaded?, _contract} 14 ) do 15 pretty_signature_args = Erlex.pretty_print_args(signature_args) 16 17 if Enum.empty?(arg_positions) do 18 # We do not know which argument(s) caused the failure 19 """ 20 will never return since the success typing arguments are 21 #{pretty_signature_args} 22 """ 23 else 24 positions = form_position_string(arg_positions) 25 26 """ 27 will never return since the #{positions} arguments differ 28 from the success typing arguments: 29 30 #{pretty_signature_args} 31 """ 32 end 33 end 34 35 def call_or_apply_to_string( 36 arg_positions, 37 :only_contract, 38 _signature_args, 39 _signature_return, 40 {overloaded?, contract} 41 ) do 42 pretty_contract = Erlex.pretty_print_contract(contract) 43 44 if Enum.empty?(arg_positions) || overloaded? do 45 # We do not know which arguments caused the failure 46 """ 47 breaks the contract 48 #{pretty_contract} 49 """ 50 else 51 position_string = form_position_string(arg_positions) 52 53 """ 54 breaks the contract 55 #{pretty_contract} 56 57 in #{position_string} argument 58 """ 59 end 60 end 61 62 def call_or_apply_to_string( 63 _arg_positions, 64 :both, 65 signature_args, 66 signature_return, 67 {_overloaded?, contract} 68 ) do 69 pretty_contract = Erlex.pretty_print_contract(contract) 70 71 pretty_print_signature = 72 Erlex.pretty_print_contract("#{signature_args} -> #{signature_return}") 73 74 """ 75 will never return since the success typing is: 76 #{pretty_print_signature} 77 78 and the contract is 79 #{pretty_contract} 80 """ 81 end 82 83 def form_position_string(arg_positions) do 84 Enum.map_join(arg_positions, " and ", &ordinal/1) 85 end 86 end