Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ _isgensym(s::Symbol) = occursin("#", string(s))
@generated function (fc::FunctionConstructor{F})(args...) where F
isempty(args) && return Expr(:new, F)

T = getfield(parentmodule(F), nameof(F))
# We assume all gensym names are anonymous functions
_isgensym(nameof(F)) || return :($T(args...))
_isgensym(nameof(F)) || return :($F(args...))
# Define `new` for rebuilt function type that matches args
exp = Expr(:new, Expr(:curly, T, args...))
exp = Expr(:new, Expr(:curly, F, args...))
for i in 1:length(args)
push!(exp.args, :(args[$i]))
end
return exp
end

function ConstructionBase.constructorof(f::Type{F}) where F <: Function
FunctionConstructor{F}()
FunctionConstructor{Base.typename(F).wrapper}()
end

Loading