warren84

warren84

Destructuring a 3-tuple throws linter warning but still works. Incompatible types: tuple() !~ {var1, var2, var3}

I would like to know what I can do to get rid of the “incompatible types” warnings that are cluttering my phoenix server logs - I would willingly accept “operator error” as the cause if I could learn how to prevent the warnings. This is essentially the same as Destructuring a 2-tuple throws linter warning but still works. Incompatible types: tuple() !~ {var1, var2} - I am also using vscode and ElixirLS - in that post, one comment said that the problem would be fixed elixir 1.13 - I’m using 1.15. The phoenix app fine despite the warnings in the logs

Any help/direction is appreciated.

++++++++++++++++++++++++++
warning: incompatible types:

tuple() !~ {var1, var2, var3}

in expression:

# lib/dancePHX/dance_parser.ex:280
{ol, bts, d_bts} = acc

where “acc” was given the type tuple() in:

# lib/dancePHX/dance_parser.ex:278
elem(acc, 1)

where “acc” was given the type {var1, var2, var3} in:

# lib/dancePHX/dance_parser.ex:280
{ol, bts, d_bts} = acc

++++++++++++++++++++++++++
the code that’s generating this warning:

def _gen_phrases(el, acc) when elem(acc, 1) < 16 do <<<— line 278
[fig, b, _c] = el
{ol, bts, d_bts} = acc

...

end

There are also _gen_phrases(el, acc) functions using elem(acc, 1) == 16 and elem(acc, 1) > 16 which generate the same warning.

I’m using phoenix 1.6.11 and elixir 1.15.6.

++++++++++++++++++++++++++
$ elixir -v
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]
Elixir 1.15.6 (compiled with Erlang/OTP 26)

Most Liked

dimitarvp

dimitarvp

Well, let me just say that I had no clue that function names could be prefixed with underscores.

03juan

03juan

I assume it’s warning that the basic tuple() type denotes tuples of any size and you’re matching it to a 3-element tuple, where it could fail.

A tuple in a pattern will match only tuples of the same size
Patterns and Guards — Elixir v1.15.6

You could explicitly match the correct shape in the function definitions:

def _gen_phrases(el, {ol, bts, d_bts} = acc) when bts == 16
# or alternatively 
# def _gen_phrases(el, {ol, bts = 16, d_bts} = acc)

def _gen_phrases(el, {ol, bts, d_bts} = acc) when bts < 16

def _gen_phrases(el, {ol, bts, d_bts} = acc) when bts > 16
# or leave out the guard as the other 2 clauses match everything <=16
christhekeele

christhekeele

Yep, they’re conventionally considered to be “hidden” (similar to double-underscore-prefixed struct fields) and will never be implicitly imported, auto-displayed in exdoc, or listed in iex helpers.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
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
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
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
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
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
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 39467 209
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement