Skip to content

Commit 924a130

Browse files
Fix rewriter for version-gated expressions (#535)
1 parent b8ab3b6 commit 924a130

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

res/wrap/wrap.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ end
147147

148148
function stripStatic(expr::Expr)
149149
if expr.head == :macrocall && first(expr.args) == Symbol("@static")
150-
return expr.args[3].args[2].args[1]
150+
return expr.args[3].args[2].args
151151
else
152-
return expr
152+
return [expr]
153153
end
154154
end
155155

@@ -176,25 +176,31 @@ function rewriter!(ctx, options)
176176

177177
nodetype = typeof(node)
178178
if nodetype <: Generators.ExprNode{<:Generators.AbstractObjCObjNodeType}
179-
declexpr = node.exprs[1]
179+
nostatic_exprs = if length(node.exprs) > 1
180+
node.exprs
181+
else
182+
stripStatic(node.exprs[1])
183+
end
184+
185+
declexpr = nostatic_exprs[1]
186+
180187
if haskey(nodedict, "immutable")
181-
declexpr = node.exprs[1]
182188
con = nodedict["immutable"]
183-
184189
declexpr.args[3].args[2] = con
185190
end
186191
if haskey(nodedict, "supertype")
187-
expr2 = stripStatic(declexpr).args[4]
192+
expr2 = declexpr.args[4]
188193
typ = nodedict["supertype"] |> Meta.parse
189194

190195
expr2.args[2] = typ
191196
end
192197
if haskey(nodedict, "proptype")
193198
proptypedict = nodedict["proptype"]
194-
propertyexprs = node.exprs[2].args[4].args
199+
200+
propertyexprs = nostatic_exprs[2].args[4].args
195201
for pro in propertyexprs
196202
isnothing(pro) && continue
197-
strippedpro = stripStatic(pro)
203+
strippedpro = stripStatic(pro)[1]
198204
propname = strippedpro.args[3].args[1]
199205
if haskey(proptypedict, string(propname))
200206
newtype = proptypedict[string(propname)] |> Meta.parse

0 commit comments

Comments
 (0)