Skip to content

Commit

Permalink
define propertynames() to be consistent with getproperty()
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin authored Dec 8, 2024
1 parent b62e257 commit 2eef9a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ end
let dimension_names = QuoteNode.([:x, :y, :z, :w])
body = :(getfield(v, name))
for (i,dim_name) in enumerate(dimension_names)
@eval @inline Base.propertynames(v::Union{SVector{$i},MVector{$i}}) = ($(first(dimension_names, i)...),)

Check warning on line 21 in src/MVector.jl

View check run for this annotation

Codecov / codecov/patch

src/MVector.jl#L21

Added line #L21 was not covered by tests

body = :(name === $(dimension_names[i]) ? getfield(v, :data)[$i] : $body)
@eval @inline function Base.getproperty(v::Union{SVector{$i},MVector{$i}},
name::Symbol)
Expand Down
2 changes: 2 additions & 0 deletions test/SVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@

@testset "Named field access - getproperty" begin
v4 = SA[10,20,30,40]
@test propertynames(v4) == (:x, :y, :z, :w)
@test v4.x == 10
@test v4.y == 20
@test v4.z == 30
@test v4.w == 40
v2 = SA[10,20]
@test propertynames(v2) == (:x, :y)
@test v2.x == 10
@test v2.y == 20
@test_throws ErrorException v2.z
Expand Down

0 comments on commit 2eef9a8

Please sign in to comment.