Skip to content

Commit

Permalink
Fix _is_attribute_storing_type (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Apr 18, 2024
1 parent 11cbec3 commit 795382d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ macro attributes(expr)
error("attributes can only be attached to mutable structs")
end

_is_attribute_storing_type(::Type{T}) where T = Base.issingletontype(T) || isstructtype(T) && ismutable(T) && hasfield(T, :__attrs)
_is_attribute_storing_type(::Type{T}) where T = Base.issingletontype(T) || isstructtype(T) && ismutabletype(T) && hasfield(T, :__attrs)

# storage for attributes of singletons
const _singleton_attr_storage = Dict{Type, Dict{Symbol, Any}}()
Expand Down
15 changes: 15 additions & 0 deletions test/Attributes-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ end
@attributes Tmp.Quux
@attributes Tmp.FooBar{Tmp.Quux}

@testset "_is_attribute_storing_type" begin
@test AbstractAlgebra._is_attribute_storing_type(Tmp.Foo)
@test AbstractAlgebra._is_attribute_storing_type(Tmp.Bar)
@test AbstractAlgebra._is_attribute_storing_type(Tmp.Quux)

@test !AbstractAlgebra._is_attribute_storing_type(Tmp.FooBar)
@test !AbstractAlgebra._is_attribute_storing_type(Tmp.FooBar{Tmp.Foo})
@test AbstractAlgebra._is_attribute_storing_type(Tmp.FooBar{Tmp.Bar})
@test AbstractAlgebra._is_attribute_storing_type(Tmp.FooBar{Tmp.Quux})

@test AbstractAlgebra._is_attribute_storing_type(Tmp.Container)
@test AbstractAlgebra._is_attribute_storing_type(Tmp.Container{Tmp.Bar})
@test AbstractAlgebra._is_attribute_storing_type(Tmp.Container{Tmp.Quux})
end

# applying @attributes to a singleton typename is supported but does nothing
@attributes Tmp.Singleton

Expand Down

0 comments on commit 795382d

Please sign in to comment.