Aetherus

Aetherus

Elixir 1.14.1 Protocol issue (Protocol.UndefinedError) - works in Elixir 1.14.0, but not in 1.14.1

The following code works in Elixir 1.14.0, but not in 1.14.1:

defprotocol Foo do
  def foo(x)
end

###################

defmodule Bar do
  defstruct []

  defimpl Foo, for: __MODULE__ do
    def foo(x) do
      ...
    end
  end
end

##################

Foo.foo(%Bar{})

In 1.14.1, when the last statement is called, the following error is raised (I was trying this in Livebook):

** (Protocol.UndefinedError) protocol Foo not implemented for %Bar{} of type Bar (a struct)
    #cell:enx47nczjxo7awjw44j4cdlxiv536l3w:1: Foo.impl_for!/1
    #cell:enx47nczjxo7awjw44j4cdlxiv536l3w:2: Foo.foo/1
    #cell:2zzjhjq5howfzuc33tjy7lttvaatqq2r:1: (file)

I compared the source code in these 2 versions, and the only difference I saw is

I don’t know if this is relevant. Please take a look. Thanks

Marked As Solved

LostKobrakai

LostKobrakai

You can do this to define an implementation for Bar, but I’m positive your version is not supposed to break as well.

defmodule Bar do
  defstruct []

  defimpl Foo do
    def foo(x) do
      ...
    end
  end
end

Also Liked

al2o3cr

al2o3cr

FWIW, this is an issue that will be fixed in 1.14.2:

https://github.com/elixir-lang/elixir/issues/12186

Aetherus

Aetherus

Thank you for your quick reply. Saved my day. :heart:

Where Next?

Popular in Questions Top

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
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
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
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
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
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
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
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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 records...
New

Other popular topics Top

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
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
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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 records...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
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
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement