@@ -347,7 +347,7 @@ defmodule Protocol do
347
347
end
348
348
349
349
defp assert_impl! ( protocol , base , extra ) do
350
- impl = Module . concat ( protocol , base )
350
+ impl = Protocol . __concat__ ( protocol , base )
351
351
352
352
try do
353
353
Code . ensure_compiled! ( impl )
@@ -678,7 +678,7 @@ defmodule Protocol do
678
678
end
679
679
680
680
defp load_impl ( protocol , for ) do
681
- Module . concat ( protocol , for )
681
+ Protocol . __concat__ ( protocol , for )
682
682
end
683
683
684
684
# Finally compile the module and emit its bytecode.
@@ -831,7 +831,7 @@ defmodule Protocol do
831
831
# Define the implementation for built-ins
832
832
:lists . foreach (
833
833
fn { guard , mod } ->
834
- target = Module . concat ( __MODULE__ , mod )
834
+ target = Protocol . __concat__ ( __MODULE__ , mod )
835
835
836
836
Kernel . def impl_for ( data ) when :erlang . unquote ( guard ) ( data ) do
837
837
case Code . ensure_compiled ( unquote ( target ) ) do
@@ -875,7 +875,7 @@ defmodule Protocol do
875
875
876
876
# Internal handler for Structs
877
877
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
879
879
{ :module , module } -> module
880
880
{ :error , _ } -> unquote ( any_impl_for )
881
881
end
@@ -948,7 +948,7 @@ defmodule Protocol do
948
948
quote do
949
949
protocol = unquote ( protocol )
950
950
for = unquote ( for )
951
- name = Module . concat ( protocol , for )
951
+ name = Protocol . __concat__ ( protocol , for )
952
952
953
953
Protocol . assert_protocol! ( protocol )
954
954
Protocol . __ensure_defimpl__ ( protocol , for , __ENV__ )
@@ -994,7 +994,7 @@ defmodule Protocol do
994
994
else
995
995
# TODO: Deprecate this on Elixir v1.22+
996
996
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 ] }
998
998
end
999
999
1000
1000
# Clean up variables from eval context
@@ -1006,7 +1006,7 @@ defmodule Protocol do
1006
1006
else
1007
1007
__ensure_defimpl__ ( protocol , for , env )
1008
1008
assert_impl! ( protocol , Any , extra )
1009
- impl = Module . concat ( protocol , Any )
1009
+ impl = Protocol . __concat__ ( protocol , Any )
1010
1010
1011
1011
funs =
1012
1012
for { fun , arity } <- protocol . __protocol__ ( :functions ) do
@@ -1031,7 +1031,11 @@ defmodule Protocol do
1031
1031
def __impl__ ( :for ) , do: unquote ( for )
1032
1032
end
1033
1033
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
+ )
1035
1039
end
1036
1040
end )
1037
1041
end
@@ -1070,4 +1074,17 @@ defmodule Protocol do
1070
1074
is_reference: Reference
1071
1075
]
1072
1076
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
1073
1090
end
0 commit comments