@@ -259,15 +259,23 @@ is_valid(unquote, Unquote) -> is_boolean(Unquote).
259259shallow_validate_ast (Expr ) ->
260260 case shallow_valid_ast (Expr ) of
261261 true -> Expr ;
262- false -> argument_error (<<" tried to unquote invalid AST: " , ('Elixir.Kernel' :inspect (Expr ))/binary >>)
262+ false -> argument_error (
263+ <<" tried to unquote invalid AST: " , ('Elixir.Kernel' :inspect (Expr ))/binary ,
264+ " \n Did you forget to escape term using Macro.escape/1?" >>)
263265 end .
264266
265- shallow_valid_ast (Expr ) when is_list (Expr ) -> lists :all (fun shallow_valid_ast /1 , Expr );
266- shallow_valid_ast (Expr ) when is_atom (Expr ); is_binary (Expr ); is_number (Expr ); is_pid (Expr ) -> true ;
267- shallow_valid_ast ({Left , Right }) -> shallow_valid_ast (Left ) andalso shallow_valid_ast (Right );
268- shallow_valid_ast ({Atom , Meta , Args }) when is_atom (Atom ), is_list (Meta ), is_atom (Args ) orelse is_list (Args ) -> true ;
269- shallow_valid_ast ({Call , Meta , Args }) when is_list (Meta ), is_list (Args ) -> shallow_valid_ast (Call );
270- shallow_valid_ast (_Term ) -> false .
267+ shallow_valid_ast (Expr ) when is_list (Expr ) -> valid_ast_list (Expr );
268+ shallow_valid_ast (Expr ) -> valid_ast_elem (Expr ).
269+
270+ valid_ast_list ([]) -> true ;
271+ valid_ast_list ([Head | Tail ]) -> valid_ast_elem (Head ) andalso valid_ast_list (Tail );
272+ valid_ast_list (_Improper ) -> false .
273+
274+ valid_ast_elem (Expr ) when is_list (Expr ); is_atom (Expr ); is_binary (Expr ); is_number (Expr ); is_pid (Expr ) -> true ;
275+ valid_ast_elem ({Left , Right }) -> valid_ast_elem (Left ) andalso valid_ast_elem (Right );
276+ valid_ast_elem ({Atom , Meta , Args }) when is_atom (Atom ), is_list (Meta ), is_atom (Args ) orelse is_list (Args ) -> true ;
277+ valid_ast_elem ({Call , Meta , Args }) when is_list (Meta ), is_list (Args ) -> shallow_valid_ast (Call );
278+ valid_ast_elem (_Term ) -> false .
271279
272280quote ({unquote_splicing , _ , [_ ]}, # elixir_quote {unquote = true }) ->
273281 argument_error (<<" unquote_splicing only works inside arguments and block contexts, "
0 commit comments