@@ -164,10 +164,19 @@ do_escape(BitString, _) when is_bitstring(BitString) ->
164164 end ;
165165
166166do_escape (Map , Q ) when is_map (Map ) ->
167- TT = do_quote (lists :sort (maps :to_list (Map )), Q ),
167+ TT =
168+ [if
169+ is_reference (V ) ->
170+ argument_error (<<('Elixir.Kernel' :inspect (Map , []))/binary , " contains a reference (" ,
171+ ('Elixir.Kernel' :inspect (V , []))/binary , " ) and therefore it cannot be escaped " ,
172+ " (it must be defined within a function instead). " , (bad_escape_hint ())/binary >>);
173+ true ->
174+ {do_quote (K , Q ), do_quote (V , Q )}
175+ end || {K , V } <- lists :sort (maps :to_list (Map ))],
168176 {'%{}' , [], TT };
169177
170- do_escape ([], _ ) -> [];
178+ do_escape ([], _ ) ->
179+ [];
171180
172181do_escape ([H | T ], # elixir_quote {unquote = false } = Q ) ->
173182 do_quote_simple_list (T , do_quote (H , Q ), Q );
@@ -199,8 +208,11 @@ do_escape(Other, _) ->
199208
200209bad_escape (Arg ) ->
201210 argument_error (<<" cannot escape " , ('Elixir.Kernel' :inspect (Arg , []))/binary , " . " ,
202- " The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, " ,
203- " PIDs and remote functions in the format &Mod.fun/arity" >>).
211+ (bad_escape_hint ())/binary >>).
212+
213+ bad_escape_hint () ->
214+ <<" The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, " ,
215+ " PIDs and remote functions in the format &Mod.fun/arity" >>.
204216
205217% % Quote entry points
206218
0 commit comments