diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d2be379..f70b68b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -17,6 +17,7 @@ jobs: - '1.3' - '1.5' - '1.6' + - '1.7' - '1' - 'nightly' os: diff --git a/Project.toml b/Project.toml index 13543cd..7611b5c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ConstructionBase" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" authors = ["Takafumi Arakaki", "Rafael Schouten", "Jan Weidner"] -version = "1.5.0" +version = "1.5.1" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/ConstructionBase.jl b/src/ConstructionBase.jl index 546eae5..6174be0 100644 --- a/src/ConstructionBase.jl +++ b/src/ConstructionBase.jl @@ -48,26 +48,37 @@ getfields(x::NamedTuple) = x getproperties(o::NamedTuple) = o getproperties(o::Tuple) = o -function is_propertynames_overloaded(T::Type)::Bool - which(propertynames, Tuple{T}).sig !== Tuple{typeof(propertynames), Any} -end - -@generated function check_properties_are_fields(obj) - if is_propertynames_overloaded(obj) - return quote - T = typeof(obj) - msg = """ - The function `Base.propertynames` was overloaded for type `$T`. - Please make sure the following methods are also overloaded for this type: - ```julia - ConstructionBase.setproperties - ConstructionBase.getproperties # optional in VERSION >= julia v1.7 - ``` - """ - error(msg) +if VERSION >= v"1.7" + function check_properties_are_fields(obj) + if propertynames(obj) != fieldnames(typeof(obj)) + error(""" + The function `Base.propertynames` was overloaded for type `$(typeof(obj))`. + Please make sure `ConstructionBase.setproperties` is also overloaded for this type. + """) + end + end +else + function is_propertynames_overloaded(T::Type)::Bool + which(propertynames, Tuple{T}).sig !== Tuple{typeof(propertynames), Any} + end + + @generated function check_properties_are_fields(obj) + if is_propertynames_overloaded(obj) + return quote + T = typeof(obj) + msg = """ + The function `Base.propertynames` was overloaded for type `$T`. + Please make sure the following methods are also overloaded for this type: + ```julia + ConstructionBase.setproperties + ConstructionBase.getproperties # optional in VERSION >= julia v1.7 + ``` + """ + error(msg) + end + else + :(nothing) end - else - :(nothing) end end