Skip to content

Commit 83d75ce

Browse files
authored
Merge pull request #75 from aplavin/fix72
fix #72
2 parents 4d661f8 + 5f08dd3 commit 83d75ce

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- '1.3'
1818
- '1.5'
1919
- '1.6'
20+
- '1.7'
2021
- '1'
2122
- 'nightly'
2223
os:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ConstructionBase"
22
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
33
authors = ["Takafumi Arakaki", "Rafael Schouten", "Jan Weidner"]
4-
version = "1.5.0"
4+
version = "1.5.1"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ConstructionBase.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,37 @@ getfields(x::NamedTuple) = x
4848
getproperties(o::NamedTuple) = o
4949
getproperties(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
7283
end
7384

0 commit comments

Comments
 (0)