opaque_equality.ex (1121B)
1 defmodule Dialyxir.Warnings.OpaqueEquality do 2 @behaviour Dialyxir.Warning 3 4 @impl Dialyxir.Warning 5 @spec warning() :: :opaque_eq 6 def warning(), do: :opaque_eq 7 8 @impl Dialyxir.Warning 9 @spec format_short([String.t()]) :: String.t() 10 def format_short([_type, _op, opaque_type]) do 11 pretty_opaque_type = opaque_type |> Erlex.pretty_print() |> unqualify_module() 12 "Attempt to test for equality with an opaque type #{pretty_opaque_type}." 13 end 14 15 defp unqualify_module(name) when is_binary(name) do 16 case String.split(name, ".") do 17 [only] -> 18 only 19 20 multiple -> 21 multiple 22 |> Enum.take(-2) 23 |> Enum.join(".") 24 end 25 end 26 27 @impl Dialyxir.Warning 28 @spec format_long([String.t()]) :: String.t() 29 def format_long([type, _op, opaque_type]) do 30 pretty_opaque_type = Erlex.pretty_print_type(opaque_type) 31 32 "Attempt to test for equality between a term of type #{type} " <> 33 "and a term of opaque type #{pretty_opaque_type}." 34 end 35 36 @impl Dialyxir.Warning 37 @spec explain() :: String.t() 38 def explain() do 39 Dialyxir.Warning.default_explain() 40 end 41 end