@@ -355,15 +355,23 @@ allowed_guard(Right, Arity) ->
355
355
erl_internal :guard_bif (Right , Arity ) orelse elixir_utils :guard_op (Right , Arity ).
356
356
357
357
format_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 " ,
359
359
['Elixir.Macro' :to_string (Receiver ), Right , Arity , Context ]);
360
360
format_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" ,
362
362
['Elixir.Macro' :to_string (Receiver ), Right , Arity ]);
363
363
format_error ({invalid_match_append , Arg }) ->
364
364
io_lib :format (" invalid argument for ++ operator inside a match, expected a literal proper list, got: ~ts " ,
365
365
['Elixir.Macro' :to_string (Arg )]).
366
366
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
+
367
375
is_always_string ({{'.' , _ , [Module , Function ]}, _ , Args }) ->
368
376
is_always_string (Module , Function , length (Args ));
369
377
is_always_string (Ast ) ->
0 commit comments