@@ -160,10 +160,19 @@ do_escape(BitString, _) when is_bitstring(BitString) ->
160160 end ;
161161
162162do_escape (Map , Q ) when is_map (Map ) ->
163- TT = do_quote (lists :sort (maps :to_list (Map )), Q ),
163+ TT =
164+ [if
165+ is_reference (V ) ->
166+ argument_error (<<('Elixir.Kernel' :inspect (Map , []))/binary , " contains a reference (" ,
167+ ('Elixir.Kernel' :inspect (V , []))/binary , " ) and therefore it cannot be escaped " ,
168+ " (it must be defined within a function instead). " , (bad_escape_hint ())/binary >>);
169+ true ->
170+ {do_quote (K , Q ), do_quote (V , Q )}
171+ end || {K , V } <- lists :sort (maps :to_list (Map ))],
164172 {'%{}' , [], TT };
165173
166- do_escape ([], _ ) -> [];
174+ do_escape ([], _ ) ->
175+ [];
167176
168177do_escape ([H | T ], # elixir_quote {unquote = false } = Q ) ->
169178 do_quote_simple_list (T , do_quote (H , Q ), Q );
@@ -195,8 +204,11 @@ do_escape(Other, _) ->
195204
196205bad_escape (Arg ) ->
197206 argument_error (<<" cannot escape " , ('Elixir.Kernel' :inspect (Arg , []))/binary , " . " ,
198- " The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, " ,
199- " PIDs and remote functions in the format &Mod.fun/arity" >>).
207+ (bad_escape_hint ())/binary >>).
208+
209+ bad_escape_hint () ->
210+ <<" The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, " ,
211+ " PIDs and remote functions in the format &Mod.fun/arity" >>.
200212
201213% % Quote entry points
202214
0 commit comments