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

1 Like

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
2 Likes

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

1 Like

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

2 Likes