@@ -540,6 +540,7 @@ defmodule Protocol do
540
540
"the dict[key] syntax, please implement the Dict behaviour instead"
541
541
else
542
542
Protocol . assert_protocol! ( protocol )
543
+ Protocol . __ensure_defimpl__ ( protocol , for , __ENV__ )
543
544
end
544
545
545
546
defmodule name do
@@ -580,6 +581,7 @@ defmodule Protocol do
580
581
defp derive ( protocol , for , struct , opts , env ) do
581
582
extra = ", cannot derive #{ inspect protocol } for #{ inspect for } "
582
583
assert_protocol! ( protocol , extra )
584
+ __ensure_defimpl__ ( protocol , for , env )
583
585
assert_impl! ( protocol , Any , extra )
584
586
585
587
# Clean up variables from eval context
@@ -608,6 +610,17 @@ defmodule Protocol do
608
610
end )
609
611
end
610
612
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
+
611
624
@ doc false
612
625
def __spec__? ( module , name , arity ) do
613
626
signature = { name , arity }
0 commit comments