diff --git a/src/macro_expansion.jl b/src/macro_expansion.jl index 1e4ac756..91c92f22 100644 --- a/src/macro_expansion.jl +++ b/src/macro_expansion.jl @@ -145,8 +145,16 @@ function expand_macro(ctx, ex) end macro_invocation_world = Base.get_world_counter() expanded = try - # TODO: Allow invoking old-style macros for compat - invokelatest(macfunc, macro_args...) + if applicable(macfunc, macro_args...) + invokelatest(macfunc, macro_args...) + else + # try old-style macro + args = (Expr(x) for x in macro_args[2:end]) + line, _ = source_location(macname) + file = filename(macname) + line_number_node = Base.LineNumberNode(line, file) + invokelatest(macfunc, line_number_node, ctx.current_layer.mod, args...) + end catch exc if exc isa MacroExpansionError # Add context to the error. diff --git a/test/macros.jl b/test/macros.jl index 6e25c326..21aacc81 100644 --- a/test/macros.jl +++ b/test/macros.jl @@ -142,4 +142,10 @@ end == [ "2" ] +# old-style generated macro, e.g. as lowered by pre-JuliaLowering lowering +@eval test_mod var"@hi"(__source__::LineNumberNode, __module__::Module) = "hi" + +# check that we can macroexpand it properly even though we don't have the new method +# that accepts a MacroExpansionContext +@test JuliaLowering.include_string(test_mod, "@hi") == "hi" end