@@ -540,6 +540,7 @@ defmodule Protocol do
540540 "the dict[key] syntax, please implement the Dict behaviour instead"
541541 else
542542 Protocol . assert_protocol! ( protocol )
543+ Protocol . __ensure_defimpl__ ( protocol , for , __ENV__ )
543544 end
544545
545546 defmodule name do
@@ -580,6 +581,7 @@ defmodule Protocol do
580581 defp derive ( protocol , for , struct , opts , env ) do
581582 extra = ", cannot derive #{ inspect protocol } for #{ inspect for } "
582583 assert_protocol! ( protocol , extra )
584+ __ensure_defimpl__ ( protocol , for , env )
583585 assert_impl! ( protocol , Any , extra )
584586
585587 # Clean up variables from eval context
@@ -608,6 +610,17 @@ defmodule Protocol do
608610 end )
609611 end
610612
613+ @ doc false
614+ def __ensure_defimpl__ ( protocol , for , env ) do
615+ if Protocol . consolidated? ( protocol ) do
616+ message =
617+ "the #{ inspect protocol } protocol has already been consolidated" <>
618+ ", an implementation for #{ inspect for } has no effect"
619+ :elixir_errors . warn ( env . line , env . file , message )
620+ end
621+ :ok
622+ end
623+
611624 @ doc false
612625 def __spec__? ( module , name , arity ) do
613626 signature = { name , arity }
0 commit comments