Skip to content

Commit

Permalink
Allow allocs for union types on older Julia versions
Browse files Browse the repository at this point in the history
  • Loading branch information
serenity4 committed Jul 27, 2024
1 parent ac65fcd commit 812884d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ConstructionBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ setproperties_object(obj, patch::NamedTuple{()}) = obj
pnames = fieldnames(patch)
for fname in fieldnames(obj)
source = fname in pnames ? :patch : :obj
push!(args, :(getfield($source, $(QuoteNode(fname)))))
push!(args, :(getproperty($source, $(QuoteNode(fname)))))
end
:(constructorof(typeof(obj))($(args...)))
end
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ end
@testset "no allocs S2" begin
obj = S2(3, UInt32(5))
@test 0 == hot_loop_allocs(constructorof, typeof(obj))
@test 0 == hot_loop_allocs(setproperties, obj, (; a = nothing, b = Int32(6)))
if VERSION v"1.3"
@test 32 == hot_loop_allocs(setproperties, obj, (; a = nothing, b = Int32(6)))
else
@test 0 == hot_loop_allocs(setproperties, obj, (; a = nothing, b = Int32(6)))
end
end

@testset "inference" begin
Expand Down

0 comments on commit 812884d

Please sign in to comment.