Skip to content

Commit

Permalink
Compat fix for ConstructionBase 1.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Aug 28, 2024
1 parent b987170 commit e1e101d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ext/LegolasConstructionBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ using Legolas: AbstractRecord
if VERSION < v"1.7"
ConstructionBase.getproperties(r::AbstractRecord) = NamedTuple(r)

# This is largely copy-paste from `ConstructionBase.setproperties_object`:
# https://github.com/JuliaObjects/ConstructionBase.jl/blob/cd24e541fd90ab54d2ee12ddd6ccd229be9a5f1e/src/ConstructionBase.jl#L211-L218
function ConstructionBase.setproperties(r::R, patch::NamedTuple) where {R<:AbstractRecord}
nt = getproperties(r)
nt_new = merge(nt, patch)
ConstructionBase.check_patch_properties_exist(nt_new, nt, r, patch)
args = Tuple(nt_new) # old Julia inference prefers if we wrap in `Tuple`
return constructorof(R)(args...)
if isdefined(ConstructionBase, :check_patch_properties_exist)
# This is largely copy-paste from `ConstructionBase.setproperties_object`:
# https://github.com/JuliaObjects/ConstructionBase.jl/blob/cd24e541fd90ab54d2ee12ddd6ccd229be9a5f1e/src/ConstructionBase.jl#L211-L218
nt = getproperties(r)
nt_new = merge(nt, patch)
ConstructionBase.check_patch_properties_exist(nt_new, nt, r, patch)
args = Tuple(nt_new) # old Julia inference prefers if we wrap in `Tuple`
return constructorof(R)(args...)

Check warning on line 23 in ext/LegolasConstructionBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LegolasConstructionBaseExt.jl#L19-L23

Added lines #L19 - L23 were not covered by tests
else
# As of ConstructionBase 1.5.7 the internals of `ConstructionBase.setproperties_object` have changed:
# https://github.com/JuliaObjects/ConstructionBase.jl/blob/71fb5a5198f41f3ef29a53c01940cf7cf6b233eb/src/ConstructionBase.jl#L205-L209
ConstructionBase.check_patch_fields_exist(r, patch)
return ConstructionBase.setfields_object(r, patch)
end
end
end

Expand Down

0 comments on commit e1e101d

Please sign in to comment.