@@ -48,26 +48,37 @@ getfields(x::NamedTuple) = x
4848getproperties(o:: NamedTuple ) = o
4949getproperties(o:: Tuple ) = o
5050
51- function is_propertynames_overloaded(T:: Type ):: Bool
52- which(propertynames, Tuple{T}). sig != = Tuple{typeof(propertynames), Any}
53- end
54-
55- @generated function check_properties_are_fields(obj)
56- if is_propertynames_overloaded(obj)
57- return quote
58- T = typeof(obj)
59- msg = """
60- The function `Base.propertynames` was overloaded for type `$T `.
61- Please make sure the following methods are also overloaded for this type:
62- ```julia
63- ConstructionBase.setproperties
64- ConstructionBase.getproperties # optional in VERSION >= julia v1.7
65- ```
66- """
67- error(msg)
51+ if VERSION >= v" 1.7"
52+ function check_properties_are_fields(obj)
53+ if propertynames(obj) != fieldnames(typeof(obj))
54+ error("""
55+ The function `Base.propertynames` was overloaded for type `$(typeof(obj)) `.
56+ Please make sure `ConstructionBase.setproperties` is also overloaded for this type.
57+ """ )
58+ end
59+ end
60+ else
61+ function is_propertynames_overloaded(T:: Type ):: Bool
62+ which(propertynames, Tuple{T}). sig != = Tuple{typeof(propertynames), Any}
63+ end
64+
65+ @generated function check_properties_are_fields(obj)
66+ if is_propertynames_overloaded(obj)
67+ return quote
68+ T = typeof(obj)
69+ msg = """
70+ The function `Base.propertynames` was overloaded for type `$T `.
71+ Please make sure the following methods are also overloaded for this type:
72+ ```julia
73+ ConstructionBase.setproperties
74+ ConstructionBase.getproperties # optional in VERSION >= julia v1.7
75+ ```
76+ """
77+ error(msg)
78+ end
79+ else
80+ :(nothing )
6881 end
69- else
70- :(nothing )
7182 end
7283end
7384
0 commit comments