Skip to content

Commit c3f586e

Browse files
nsajkovtjnash
andauthored
remove UB from FunctionConstructor (#104)
* remove no-op UB from FunctionConstructor * fix * Update functions.jl --------- Co-authored-by: Jameson Nash <[email protected]>
1 parent 2e5a567 commit c3f586e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/functions.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ _isgensym(s::Symbol) = occursin("#", string(s))
88
@generated function (fc::FunctionConstructor{F})(args...) where F
99
isempty(args) && return Expr(:new, F)
1010

11-
T = getfield(parentmodule(F), nameof(F))
1211
# We assume all gensym names are anonymous functions
13-
_isgensym(nameof(F)) || return :($T(args...))
12+
_isgensym(nameof(F)) || return :($F(args...))
1413
# Define `new` for rebuilt function type that matches args
15-
exp = Expr(:new, Expr(:curly, T, args...))
14+
exp = Expr(:new, Expr(:curly, F, args...))
1615
for i in 1:length(args)
1716
push!(exp.args, :(args[$i]))
1817
end
1918
return exp
2019
end
2120

2221
function ConstructionBase.constructorof(f::Type{F}) where F <: Function
23-
FunctionConstructor{F}()
22+
FunctionConstructor{Base.typename(F).wrapper}()
2423
end
2524

0 commit comments

Comments
 (0)