Skip to content

Commit

Permalink
fix @hyperopt for upcoming base changes
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Aug 12, 2021
1 parent 3d1eb0d commit e4ce3c6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Hyperopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,18 @@ function preprocess_expression(ex)
params = (params...,)
funname = gensym(:hyperopt_objective)
state_ = :(state = nothing)
body = ex.args[2]
# remove trailing LineNumberNodes from loop body as to not just return `nothing`
if Meta.isexpr(body, :block) && body.args[end] isa LineNumberNode
resize!(body.args, length(body.args) - 1)
end
fun = quote # produces a function(i, pars...)
function $(funname)($(Expr(:tuple, esc.(params)...))...)
$(esc(state_))
$(esc(ex.args[2]))
$(esc(body))
end
function $(funname)($(esc(params[1])), $(esc(:state)))
$(esc(ex.args[2]))
$(esc(body))
end
end

Expand Down

0 comments on commit e4ce3c6

Please sign in to comment.