From 924a13037368f007b738fcf32654f3ecbb2bf939 Mon Sep 17 00:00:00 2001 From: Christian Guinard <28689358+christiangnrd@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:19:56 -0400 Subject: [PATCH] Fix rewriter for version-gated expressions (#535) --- res/wrap/wrap.jl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/res/wrap/wrap.jl b/res/wrap/wrap.jl index d958ea5b8..d66998b05 100644 --- a/res/wrap/wrap.jl +++ b/res/wrap/wrap.jl @@ -147,9 +147,9 @@ end function stripStatic(expr::Expr) if expr.head == :macrocall && first(expr.args) == Symbol("@static") - return expr.args[3].args[2].args[1] + return expr.args[3].args[2].args else - return expr + return [expr] end end @@ -176,25 +176,31 @@ function rewriter!(ctx, options) nodetype = typeof(node) if nodetype <: Generators.ExprNode{<:Generators.AbstractObjCObjNodeType} - declexpr = node.exprs[1] + nostatic_exprs = if length(node.exprs) > 1 + node.exprs + else + stripStatic(node.exprs[1]) + end + + declexpr = nostatic_exprs[1] + if haskey(nodedict, "immutable") - declexpr = node.exprs[1] con = nodedict["immutable"] - declexpr.args[3].args[2] = con end if haskey(nodedict, "supertype") - expr2 = stripStatic(declexpr).args[4] + expr2 = declexpr.args[4] typ = nodedict["supertype"] |> Meta.parse expr2.args[2] = typ end if haskey(nodedict, "proptype") proptypedict = nodedict["proptype"] - propertyexprs = node.exprs[2].args[4].args + + propertyexprs = nostatic_exprs[2].args[4].args for pro in propertyexprs isnothing(pro) && continue - strippedpro = stripStatic(pro) + strippedpro = stripStatic(pro)[1] propname = strippedpro.args[3].args[1] if haskey(proptypedict, string(propname)) newtype = proptypedict[string(propname)] |> Meta.parse