@@ -355,15 +355,23 @@ allowed_guard(Right, Arity) ->
355355 erl_internal :guard_bif (Right , Arity ) orelse elixir_utils :guard_op (Right , Arity ).
356356
357357format_error ({invalid_guard , Receiver , Right , Arity , Context }) ->
358- io_lib :format (" cannot invoke remote function ~ts .~ts /~B inside a ~ts " ,
358+ io_lib :format (cannot_invoke_or_maybe_require ( Receiver , Right , Arity ) ++ " ~ts .~ts /~B inside a ~ts " ,
359359 ['Elixir.Macro' :to_string (Receiver ), Right , Arity , Context ]);
360360format_error ({invalid_match , Receiver , Right , Arity }) ->
361- io_lib :format (" cannot invoke remote function ~ts .~ts /~B inside a match" ,
361+ io_lib :format (cannot_invoke_or_maybe_require ( Receiver , Right , Arity ) ++ " ~ts .~ts /~B inside a match" ,
362362 ['Elixir.Macro' :to_string (Receiver ), Right , Arity ]);
363363format_error ({invalid_match_append , Arg }) ->
364364 io_lib :format (" invalid argument for ++ operator inside a match, expected a literal proper list, got: ~ts " ,
365365 ['Elixir.Macro' :to_string (Arg )]).
366366
367+ cannot_invoke_or_maybe_require (Receiver , Fun , Arity ) ->
368+ try
369+ true = lists :member ({Fun , Arity }, Receiver :'__info__' (macros )),
370+ [" you must require the module" , 'Elixir.Macro' :to_string (Receiver ), " before invoking macro" ]
371+ catch
372+ _ :_ -> " cannot invoke remote function"
373+ end .
374+
367375is_always_string ({{'.' , _ , [Module , Function ]}, _ , Args }) ->
368376 is_always_string (Module , Function , length (Args ));
369377is_always_string (Ast ) ->
0 commit comments