dmarcoux
How to fix this Dialyzer warning "The guard clause can never succeed."
Hi,
I started contributing to a project where the CI checks for Dialyzer warnings. There is this code where I inverted the condition and branches of an if/else statement to make it a tiny bit easier to read.
The code in question:
def create_friend_request(from_user_id, to_user_id) do
{allowed, reason} = can_send_friend_request_with_reason?(from_user_id, to_user_id)
if allowed do
(...)
else
(...)
end
end
Previously, it was if not allowed do and Dialyzer was fine with it. Now, Dialyzer emits this warning for the line if allowed do: The guard clause can never succeed.
This is how can_send_friend_request_with_reason? is defined:
@spec can_send_friend_request_with_reason?(T.userid(), T.userid()) ::
{true, :ok} | {false, String.t()}
defdelegate can_send_friend_request_with_reason?(from_id, to_id), to: FriendRequestLib
I don’t have much experience with Dialyzer, so I wonder if I am missing something obvious?
In case you need more context than this, this is all happening in this PR. Thank you ![]()
Most Liked
NobbZ
Without your refactor but with these lines removed (teiserver/.dialyzer_ignore.exs at main · beyond-all-reason/teiserver · GitHub) is your line or function being warned about?
Given the nearly 220 lines long dialyzer ignore, they can as well remove dialyzer completely.
Until proven otherwise, I assume that your refactor just uncovered an issue again that was hidden before.
Instead of silencing all the warnings, they should get fixed.
NobbZ
The problem with ignored dialyzer warnings, they bubble up, and will explode elsewhere eventually.
So if there is an ignored warning somewhere in the callchain, it might now just blow up, though without knowing what that ignored warning is, its hard to tell why it blows after the refactor but not before.
Personally I refuse to accomodate dialyzer in projects like this. If dialyzer is used and “enforced”, then there shouldn’t be any ignored warnings, and if there are, there should be a comment explaining every single entry in the ignore file.
In cases like the one you have now, I would just add an entry to the ignore file.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









