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:

Aetherus

Aetherus

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

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
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
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
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
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
electic
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

Other popular topics Top

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
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
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
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
electic
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
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement