dcrck

dcrck

Confusing dialyzer warning: The pattern can never match the type

Hi, a user found an issue when attempting to use my Ultraviolet library: Unexpected Dialyzer issue · Issue #1 · dcrck/ultraviolet · GitHub

defmodule MyModule do
  require Logger

  def testing do
    sport_color = "pink"

    case Ultraviolet.new(sport_color) do
      {:error, m} -> Logger.error("should_not_happen", reason: m)
      {:ok, color} -> color
    end
  end
end

error :

lib/my_module.ex:9:pattern_match
The pattern can never match the type.

Pattern:
{:ok, _color}

Type:
{:error, _}

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2

Here’s a repository where I can reproduce the issue:

The warning doesn’t really make much sense to me, as I’ve used Color.new() in a variety of tests without encountering error cases, so I don’t know why dialyzer would see no path forward but the error case for a case I’ve definitely tested. Regardless, I’ve been working at this for a few hours now and I can’t seem to resolve this issue. Here’s what I’ve tried so far:

  • fixing all the dialyzer warnings / errors in Ultraviolet. While the published version still has warnings, the main branch does not. I’ve edited mix.exs on the example repository to point to my local copy with all the warnings resolved.
  • expanded the metaprogramming construct I use to generate function signatures for the W3CX11 named colors.
  • overriding the function to force a return type of {:ok, %Color{}} in an attempt to get something working.

None of these seem to work. Does anyone have any suggestions for how I might solve this problem? Thanks!

Marked As Solved

dcrck

dcrck

Okay, this took an embarrassingly long time to figure out, but since I was debugging the issue with the local version of my library, dialyzer did not even check for code changes to update the PLT (see this dialixir issue)! You need to use the --force-check argument in this case, i.e. mix dialyzer --force-check That should update the PLT accordingly. (TIL)

Now the checks pass without any issues. :sweat_smile:

Also Liked

LostKobrakai

LostKobrakai

Dialyzer doesn‘t care for what happens when the code actually runs. It cannot run it. It just cares for inferred types and how manual specs improve them.

You‘d want to figure out where dialyzer goes of the rails. One of its problems is that it will report the violation at a higher place in a callstack than where the source of the problem is. E.g. some of the helper functions to construct a color might have type inferred or speced wrongly.

dcrck

dcrck

I think that particular error is due to the presence of a check for the optional Jason dependency to generate the proper function signatures at compile time (See lib/ultraviolet/color_brewer.ex). Future versions of the library will require 1.18 and use the built-in JSON parser introduced in that release, so this warning should go away.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New

We're in Beta

About us Mission Statement