Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning 'protocol has already been consolidated' when recompiling #5228

Closed
beno opened this issue Sep 19, 2016 · 18 comments
Closed

Warning 'protocol has already been consolidated' when recompiling #5228

beno opened this issue Sep 19, 2016 · 18 comments

Comments

@beno
Copy link

beno commented Sep 19, 2016

When I add a protocol implementation such as the following, I run into a waring when recompiling:

defimpl Poison.Encoder, for: BSON.ObjectId do
  def encode(id, options) do
    BSON.ObjectId.encode!(id) |> Poison.Encoder.encode(options)
  end
end

produces on recompile

warning: the Poison.Encoder protocol has already been consolidated, an implementation for BSON.ObjectId has no effect

Using Elixir 1.3.2, for more info see elixir-mongo/mongodb#46 (comment)

@ericmj
Copy link
Member

ericmj commented Sep 19, 2016

This happens when calling recompile/0 in iex.

@liveresume
Copy link

I believe this is happening to you on auto-recompile as it is for me.

If you make changes to the Encoder you have to stop the app and restart to see the changes.

@josevalim josevalim added this to the v1.4.0 milestone Nov 20, 2016
@chaoqu
Copy link

chaoqu commented Jun 24, 2019

has this regressed? I am using Elixir 1.9.0-rc.0 (aad7aa4) (compiled with Erlang/OTP 20)

@supernintendo
Copy link

This seems to have regressed. I am using Elixir 1.8.1 with Erlang/OTP 20 and get the warning any time changed files are auto-recompiled in development.

@noelia-lencina
Copy link

I'm seeing the same warning with 1.8.2 compiled for Erlang/OTP 21. I can reproduce it every time by running r/1 in the iex console with the name of the module that's implementing the protocol (in this case the protocol is Phoenix.HTML.Safe).

@augnustin
Copy link

Same here, happens at recompilation with

elixir --version
Erlang/OTP 21 [erts-10.3.5.6] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Elixir 1.8.2 (compiled with Erlang/OTP 21)

Would be cleaner without it. 😄

@KalvinHom
Copy link

KalvinHom commented Aug 26, 2020

Hitting this all the time as well, cannot auto-recompile at all, have to manually restart the server if we use --warnings-as-errors, have to restart server for any change.

Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [hipe]
Elixir 1.9.0 (compiled with Erlang/OTP 20)

@nathanaelsousa
Copy link

Including: consolidate_protocols: Mix.env() != :dev in mix.exs seems to have solved it for me.
Like suggested here: https://hexdocs.pm/elixir/Protocol.html#module-consolidation

@bcardarella
Copy link
Contributor

I'm hitting this today, I cannot resolve the warning even after adding the above mentioned changed to mix.exs

@josevalim
Copy link
Member

@bcardarella can you try deleting _build and let me know if it works after that? I think I know why the change may not be propagating after the project is compiled.

@bcardarella
Copy link
Contributor

@josevalim still happening, fwiw this is in VSCode. I'm not sure if there are build artifacts that I would need to clear out otherwise.

@josevalim
Copy link
Member

@bcardarella they use a separate folder, _elixir_ls or .elixir_ls or similar.

@bcardarella
Copy link
Contributor

Yeah I deleted those too, no success unfortunately. After I get this lib pushed to GH I can note the LOC here to see if I'm doing anything wrong

@josevalim
Copy link
Member

If you can't reproduce it in regular code, only inside the Visual Studio Code, then it is probably best to report the issue there first. :)

@dennym
Copy link

dennym commented Jan 22, 2024

Just hijacking this issue quickly. Currently running in this issue with Poison and the usage of defimpl.

 the Poison.Decoder protocol has already been consolidated, an implementation for Foo.Bar has no effect. If you want to implement protocols after compilation or during tests, check the "Consolidation" section in the Protocol module documentation
    │
  5 │ defimpl Poison.Decoder, for: Foo.Bar do
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ lib/foo/bar.ex:5: (file)

This happens when using recompile/0 in iex -S mix. Usually after this I also have to hit a mix clean. Killing and restarting the iex does not lead to this issue.

Erlang/OTP 26
Elixir 1.16.0

This has no additonal tooling which could interfere and its on lain old zsh/bash.

@juped
Copy link

juped commented Aug 19, 2024

this occurs if you touch anything in a module with a defimpl / derived impl and recompile without a full clean build, although if you touched the impl it still gets used

minimal reproduction:

  • mix new
  • put the following in lib/s.ex
defmodule S do
  @derive {Inspect, only: []}
  defstruct [:field]
end
  • iex -S mix
  • change the module in any way, i added def a do end to it
  • recompile/0 from iex

if you instead kill iex and start a new one, it recompiles without generating warnings. however, if you ever use recompile/0, the warnings will stick around permanently until you do a clean build.

@juped
Copy link

juped commented Aug 19, 2024

(the impl works fine even if it's edited, by the way.)

@josevalim
Copy link
Member

Thank you, I have fixed it in main and I will backport to v1.17 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests