Rich_Morin

Rich_Morin

Dialyzer says "The pattern false can never match the type true"

I’ve gotten my (10 KLOC) project down to a single Dialyzer error, but I can’t figure this one out. Suggestions?

See this gist for the code.

Most Liked

Rich_Morin

Rich_Morin

After trying a few versions, I discovered bugs in a couple of @spec lines, further down in my code. For example:

@spec parse_h1(s, atom) :: map|{atom, s}
  when s: String.t

should have been:

@spec parse_h1(s, atom) :: {atom, map|s}
  when s: String.t

I think the main lessons from this are that

  • Dialyzer errors can be quite misleading about specifics.
  • Small code bases simplify testing and reduce confusion.
  • Divide and conquer is (as always) a powerful technique.

Anyway, thanks to everyone for your help!

LostKobrakai

LostKobrakai

Test files are just plain elixir scripts, which are executed on demand by the test runner. The only thing different to arbitrary elixir scripts is their folder + naming schema (*_test.exs). They‘re not part of your compiled codebase even when running with MIX_ENV=test, which is why dialyzer doesn‘t act on them.

rodrigues

rodrigues

I rewrote it as this:

  @spec filter({atom, any}, String.t()) :: map
  defp filter({:error, payload}, trim_path) do
    IO.puts("\nIgnored: " <> trim_path)
    IO.puts("Because: " <> inspect(payload))
    %{}
  end

  defp filter({_status, payload}, trim_path) do
    payload
  end

And dialyzer still failed:

apps/info_toml/lib/info_toml/parser.ex:86:pattern_match_cov
The pattern
{__status, _payload}, _trim_path

can never match since previous clauses completely cover the type
{:error, binary()}, binary()

This means dialyzer considers it will always return {:error, "..."}, so never succeed with an {:ok, map}. :face_with_monocle:

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New

Other popular topics Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement