@@ -347,7 +347,7 @@ defmodule Protocol do
347347 end
348348
349349 defp assert_impl! ( protocol , base , extra ) do
350- impl = Module . concat ( protocol , base )
350+ impl = Protocol . __concat__ ( protocol , base )
351351
352352 try do
353353 Code . ensure_compiled! ( impl )
@@ -678,7 +678,7 @@ defmodule Protocol do
678678 end
679679
680680 defp load_impl ( protocol , for ) do
681- Module . concat ( protocol , for )
681+ Protocol . __concat__ ( protocol , for )
682682 end
683683
684684 # Finally compile the module and emit its bytecode.
@@ -831,7 +831,7 @@ defmodule Protocol do
831831 # Define the implementation for built-ins
832832 :lists . foreach (
833833 fn { guard , mod } ->
834- target = Module . concat ( __MODULE__ , mod )
834+ target = Protocol . __concat__ ( __MODULE__ , mod )
835835
836836 Kernel . def impl_for ( data ) when :erlang . unquote ( guard ) ( data ) do
837837 case Code . ensure_compiled ( unquote ( target ) ) do
@@ -875,7 +875,7 @@ defmodule Protocol do
875875
876876 # Internal handler for Structs
877877 Kernel . defp struct_impl_for ( struct ) do
878- case Code . ensure_compiled ( Module . concat ( __MODULE__ , struct ) ) do
878+ case Code . ensure_compiled ( Protocol . __concat__ ( __MODULE__ , struct ) ) do
879879 { :module , module } -> module
880880 { :error , _ } -> unquote ( any_impl_for )
881881 end
@@ -948,7 +948,7 @@ defmodule Protocol do
948948 quote do
949949 protocol = unquote ( protocol )
950950 for = unquote ( for )
951- name = Module . concat ( protocol , for )
951+ name = Protocol . __concat__ ( protocol , for )
952952
953953 Protocol . assert_protocol! ( protocol )
954954 Protocol . __ensure_defimpl__ ( protocol , for , __ENV__ )
@@ -994,7 +994,7 @@ defmodule Protocol do
994994 else
995995 # TODO: Deprecate this on Elixir v1.22+
996996 assert_impl! ( protocol , Any , extra )
997- { Module . concat ( protocol , Any ) , [ for , Macro . struct! ( for , env ) , opts ] }
997+ { Protocol . __concat__ ( protocol , Any ) , [ for , Macro . struct! ( for , env ) , opts ] }
998998 end
999999
10001000 # Clean up variables from eval context
@@ -1006,7 +1006,7 @@ defmodule Protocol do
10061006 else
10071007 __ensure_defimpl__ ( protocol , for , env )
10081008 assert_impl! ( protocol , Any , extra )
1009- impl = Module . concat ( protocol , Any )
1009+ impl = Protocol . __concat__ ( protocol , Any )
10101010
10111011 funs =
10121012 for { fun , arity } <- protocol . __protocol__ ( :functions ) do
@@ -1031,7 +1031,11 @@ defmodule Protocol do
10311031 def __impl__ ( :for ) , do: unquote ( for )
10321032 end
10331033
1034- Module . create ( Module . concat ( protocol , for ) , [ quoted | funs ] , Macro.Env . location ( env ) )
1034+ Module . create (
1035+ Protocol . __concat__ ( protocol , for ) ,
1036+ [ quoted | funs ] ,
1037+ Macro.Env . location ( env )
1038+ )
10351039 end
10361040 end )
10371041 end
@@ -1070,4 +1074,17 @@ defmodule Protocol do
10701074 is_reference: Reference
10711075 ]
10721076 end
1077+
1078+ @ doc false
1079+ def __concat__ ( left , right ) do
1080+ String . to_atom (
1081+ ensure_prefix ( Atom . to_string ( left ) ) <> "." <> remove_prefix ( Atom . to_string ( right ) )
1082+ )
1083+ end
1084+
1085+ defp ensure_prefix ( "Elixir." <> _ = left ) , do: left
1086+ defp ensure_prefix ( left ) , do: "Elixir." <> left
1087+
1088+ defp remove_prefix ( "Elixir." <> right ) , do: right
1089+ defp remove_prefix ( right ) , do: right
10731090end
0 commit comments