Skip to content

Commit d9738ac

Browse files
committed
Don't drop required macro arguments in longdef1
The LineNumberNode that's the first argument to a macrocall Expr is required and dropping it causes bad errors such the one in JuliaPy/PyCall.jl#479
1 parent 99e76b8 commit d9738ac

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/utils.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ Remove the line nodes from a block or array of expressions.
5252
Compare `quote end` vs `rmlines(quote end)`
5353
"""
5454
rmlines(x) = x
55-
rmlines(x::Expr) = Expr(x.head, filter(x->!isline(x), x.args)...)
55+
function rmlines(x::Expr)
56+
# Do not strip the first argument to a macrocall, which is
57+
# required.
58+
if x.head == :macrocall && length(x.args) >= 2
59+
Expr(x.head, x.args[1:2]..., filter(x->!isline(x), x.args[3:end])...)
60+
else
61+
Expr(x.head, filter(x->!isline(x), x.args)...)
62+
end
63+
end
5664

5765
striplines(ex) = prewalk(rmlines, ex)
5866

test/runtests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ macro splitcombine(fundef) # should be a no-op
9696
esc(MacroTools.combinedef(dict))
9797
end
9898

99+
# Macros for testing that splitcombine doesn't break
100+
# macrocalls in bodies
101+
macro zeroarg()
102+
:(1)
103+
end
104+
macro onearg(x)
105+
:(1+$(esc(x)))
106+
end
107+
99108
let
100109
# Ideally we'd compare the result against :(function f(x)::Int 10 end),
101110
# but it fails because of :line and :block differences
@@ -120,6 +129,10 @@ let
120129
@test fwhere(10) == Int
121130
@splitcombine manywhere(x::T, y::Vector{U}) where T <: U where U = (T, U)
122131
@test manywhere(1, Number[2.0]) == (Int, Number)
132+
@splitcombine fmacro0() = @zeroarg
133+
@test fmacro0() == 1
134+
@splitcombine fmacro1() = @onearg 1
135+
@test fmacro1() == 2
123136

124137
struct Foo{A, B}
125138
a::A

0 commit comments

Comments
 (0)