I am trying to make my library(https://github.com/CrowdHailer/OK) for working with result tuples play nicely with dialyzer.
At them moment there is code that raises a nice error if incorrect data input is given. However dialyzer points out that this case is never needed. I still want to keep this error case. it's very helpful to explain the error to new users of the library but I want to make dialyzer ignore it.
quote location: :keep do
case unquote(right) do
{:ok, unquote(left)} ->
unquote(expand_bindings(rest, yield_block, exception_clauses))
{:error, reason} ->
{:error, reason}
case reason do
unquote(exception_clauses)
end
# This block will never be called, as far as dialyzer is concerned
# However I want to keep it for the cases when diayzer is not being used in the project
return ->
raise %OK.BindError{
return: return,
lhs: unquote(Macro.to_string(left)),
rhs: unquote(Macro.to_string(right))
}
end
end
The source can be seen here https://github.com/CrowdHailer/OK/blob/431142204794e1702271c86d6594ce76b8978b57/lib/ok.ex#L512-L529