VictorGaiva
No escape hatch for typing error
I’m currently migrating my codebase to Elixir 1.18.2. I was able to solve all the typing issues, except for one. The following code:
defmodule Run do
def test do
try do
Code.compile_string("a + ")
rescue
e ->
case e do
%{column: column, snippet: %{offset: offset}} ->
{:error, column + offset}
_ ->
{:error, :unknown}
end
end
end
end
Gives me the following compilation warning:
This could be solved by adding guards, that will allow for infering the types in a future release. But at the moment I’m not able to migrate this code and there is no scapehatch for it.
First Post!
VictorGaiva
Ah, I was able to workaround this warning by creating a ‘sum/2’ function. Since the type checking doesn’t flow throught functions, it works fine.
0
Most Liked
VictorGaiva
Sure
defmodule Run do
def test do
try do
Code.compile_string("a + ")
rescue
e ->
case e do
%{column: column, snippet: %{offset: offset}} ->
{:error, sum(column, offset)}
_ ->
{:error, :unknown}
end
end
end
def sum(a, b) do
a + b
end
end
1
Popular in Questions
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I would like to know what is the best IDE for elixir development?
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
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
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
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Other popular topics
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
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
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...
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
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










