@@ -79,27 +79,28 @@ function parse_arglist!(exprs, args, kwargs, is_kwarg_list=false)
7979end
8080
8181# Find a :call expression within an Expr. This will take care of ignoring other
82- # tokens like `where` clauses.
83- function find_call_expr (expr:: Expr )
84- if Meta. isexpr (expr, :macrocall ) && expr. args[1 ] === Symbol (" @generated" )
85- # If this is a generated function, find the first := expr to find
86- # the :call expr.
87- assignment_idx = findfirst (x -> x isa Expr && Meta. isexpr (x, :(= )), expr. args)
82+ # tokens like `where` clauses. It will return `nothing` if a :call expression
83+ # wasn't found.
84+ function find_call_expr (obj)
85+ if Meta. isexpr (obj, :call )
86+ # Base case: we've found the :call expression
87+ return obj
88+ elseif obj isa Symbol || (obj isa Expr && isempty (obj. args))
89+ # Base case: this is the end of a branch in the expression tree
90+ return nothing
91+ end
8892
89- expr. args[assignment_idx]. args[1 ]
90- elseif Meta. isexpr (expr, :(= ))
91- find_call_expr (expr. args[1 ])
92- elseif Meta. isexpr (expr, :where )
93- # Function with one or more `where` clauses
94- find_call_expr (expr. args[1 ])
95- elseif Meta. isexpr (expr, :function )
96- find_call_expr (expr. args[1 ])
97- elseif Meta. isexpr (expr, :call )
98- expr
99- else
100- Meta. dump (expr)
101- error (" Can't parse current expr (printed above)" )
93+ # Recursive case: recurse over all the Expr arguments
94+ for arg in obj. args
95+ if arg isa Expr
96+ result = find_call_expr (arg)
97+ if ! isnothing (result)
98+ return result
99+ end
100+ end
102101 end
102+
103+ return nothing
103104end
104105
105106# Parse an expression to find a :call expr, and return as much information as
0 commit comments