freewebwithme

freewebwithme

Dialyzer warning on pattern match using :atom

I have two function clauses

 @spec some_function(integer(), :unavailable) ::
          {:ok, User.t()} | {:error, Ecto.Changeset.t()}
  def some_function(id, :unavailable) do

 @spec some_function(integer(), :waiting | :working) ::
          {:ok, User.t()} | {:error, Ecto.Changeset.t()}
  def some_function(id, state) do

call this function

SomeModule.some_function(3, :waiting)

This will raise warning from dialyzer.
Is there better way to implement this function? or I can ignore warning?

First Post!

al2o3cr

al2o3cr

What warning?

Depending on the specific message, this thread may be relevant:

Most Liked

gpopides

gpopides

the warning probably is about defining twice the spec. Use 1 spec for both functions

@spec some_function(integer(), :unavailable | :waiting | :warning) ::
          {:ok, User.t()} | {:error, Ecto.Changeset.t()}

Last Post!

al2o3cr

al2o3cr

That message implies that some_functions spec has been parsed as if it was written:

@spec some_function(integer(), :atom) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}
@spec some_function(integer(), binary(), :unavailable) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()}

which explains why Dialyzer is complaining - some_function(3, :waiting) doesn’t match either of those.

A followup question - why does the compiler think the spec is like that? - is harder to answer.

A good first step would be removing the _build directory in the project to regenerate all the compiled BEAM files; this may not fix the problem but it definitely won’t make things any worse.

If you’re using a language server, check its documentation to see if it has any other artifact hoards that might need clearing.

Where Next?

Popular in Questions Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement