Skip to content

Nested macros using splitdef/combinedef #10

@tk3369

Description

@tk3369

I happened to build two macros that uses splitdef and combinedef functions. When I tried to use them together, splitdef gives an error. Looks like it doesn't expand the inner macro before applying the outer macro. Is this a ExprTools problem or could I fix it some other way? thanks

Here's a MWE:

macro foo(ex)
    esc(combinedef(splitdef(ex)))
end

macro bar(ex)
    esc(combinedef(splitdef(ex)))
end

Error as follows:

julia> @foo @bar f(x)
ERROR: LoadError: ArgumentError: Function definition contains invalid function head `:macrocall`
Expr
  head: Symbol macrocall
  args: Array{Any}((3,))
    1: Symbol @bar
    2: LineNumberNode
      line: Int64 1
      file: Symbol REPL[52]
    3: Expr
      head: Symbol call
      args: Array{Any}((2,))
        1: Symbol f
        2: Symbol x

Stacktrace:
 [1] invalid_def at /Users/tomkwong/.julia/packages/ExprTools/xk0OO/src/function.jl:30 [inlined]
 [2] splitdef(::Expr; throw::Bool) at /Users/tomkwong/.julia/packages/ExprTools/xk0OO/src/function.jl:37
 [3] splitdef(::Expr) at /Users/tomkwong/.julia/packages/ExprTools/xk0OO/src/function.jl:24
 [4] @foo(::LineNumberNode, ::Module, ::Any) at ./REPL[40]:2
in expression starting at REPL[52]:1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions