diff --git a/src/MVector.jl b/src/MVector.jl index 2819078f..f06db226 100644 --- a/src/MVector.jl +++ b/src/MVector.jl @@ -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)...),) + body = :(name === $(dimension_names[i]) ? getfield(v, :data)[$i] : $body) @eval @inline function Base.getproperty(v::Union{SVector{$i},MVector{$i}}, name::Symbol) diff --git a/test/SVector.jl b/test/SVector.jl index 2e62f479..a620312d 100644 --- a/test/SVector.jl +++ b/test/SVector.jl @@ -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