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
Most Liked
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
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.
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









