From e1e101de0d56471687796219da4eeebcbc2c3803 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 28 Aug 2024 15:07:18 -0500 Subject: [PATCH] Compat fix for ConstructionBase 1.5.7 --- ext/LegolasConstructionBaseExt.jl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ext/LegolasConstructionBaseExt.jl b/ext/LegolasConstructionBaseExt.jl index 4031d7d..b647add 100644 --- a/ext/LegolasConstructionBaseExt.jl +++ b/ext/LegolasConstructionBaseExt.jl @@ -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...) + 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