overlapping_contract.ex (1179B)
1 defmodule Dialyxir.Warnings.OverlappingContract do 2 @moduledoc """ 3 The function has an additional @spec that is already covered more 4 generally by a higher @spec. 5 6 ## Example 7 8 defmodule Example do 9 @spec ok(atom) :: :ok 10 def ok(:ok) do 11 :ok 12 end 13 14 @spec ok(:error) :: :ok 15 def ok(:error) do 16 :ok 17 end 18 end 19 """ 20 @behaviour Dialyxir.Warning 21 22 @impl Dialyxir.Warning 23 @spec warning() :: :overlapping_contract 24 def warning(), do: :overlapping_contract 25 26 @impl Dialyxir.Warning 27 @spec format_short([String.t()]) :: String.t() 28 def format_short([_module, function, arity]) do 29 "The contract for #{function}/#{arity} is overloaded." 30 end 31 32 @impl Dialyxir.Warning 33 @spec explain() :: String.t() 34 def explain() do 35 @moduledoc 36 end 37 38 @impl Dialyxir.Warning 39 @spec format_long([String.t()]) :: String.t() 40 def format_long([module, function, arity]) do 41 pretty_module = Erlex.pretty_print(module) 42 43 """ 44 Overloaded contract for #{pretty_module}.#{function}/#{arity} has 45 overlapping domains; such contracts are currently unsupported and 46 are simply ignored. 47 """ 48 end 49 end