ken-kost
Elixir v1.19 then compile warning
Following this and I’m wondering the deets about it. ![]()
I made a simple recreation:
def hello(map) do
map
|> Map.to_list()
|> Enum.reduce_while(%{}, fn {key, value}, acc ->
if value == 2 do
{:halt, :error}
else
{:cont, Map.put(acc, key, value)}
end
end)
|> then(fn
%{a: a} = data when a == 3 ->
%{data | b: a}
data ->
data
end)
|> case do
:error -> "It's error"
data -> "It's okay #{data.a}"
end
end
This produces the warning:
warning: the following clause will never match:
:error
because it attempts to match on the result of:
(fn
%{a: a} = data when a == 3 -> %{data | b: a}
data -> data
end).(
Enum.reduce_while(Map.to_list(map), %{}, fn {key, value}, acc ->
if value == 2 do
{:halt, :error}
else
{:cont, Map.put(acc, key, value)}
end
end)
)
which has type:
dynamic(%{..., a: term(), b: term()})
typing violation found at:
│
33 │ :error -> "It's error"
│ ~~~~~~~~~~~~~~~~~~~~~~
│
└─ lib/then_case.ex:33: ThenCase.hello/1
It’s like putting the first clause in then makes the compiler think the data variable is always dynamic(%{..., a: term(), b: term()}).
Removing that clause or moving it inside case (inside then or removing then and just case) resolves the warning.
It seems the compiler does not like cases made with then. ![]()
I’m just curious, is this the expected behavior and what’s the reason behind it? ![]()
Marked As Solved
josevalim
Creator of Elixir
Popular in Questions
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
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
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
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
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
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
Other popular topics
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
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









