Skip to content

Commit

Permalink
Fix show for const properties of type Vector or Symbol (#29)
Browse files Browse the repository at this point in the history
* fix access to empty vector for const fields

* trigger CI

* fix syntax error and printing of symbols

* don't print in tests

---------

Co-authored-by: Simon Christ <SimonChrist@gmx.de>
  • Loading branch information
SteffenPL and BeastyBlacksmith authored Nov 10, 2023
1 parent d1db7a1 commit 872efcc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ macro proto(expr)
end

function Base.show(io::IO, o::$name)
vals = join([x[] isa String ? "\"$(x[])\"" : x[] for x in getfield(o, :properties)], ", ")
vals = join([x isa Base.RefValue ? (x[] isa String ? "\"$(x[])\"" : x[]) : x for x in getfield(o, :properties)], ", ")
params = typeof(o).parameters[1:end-$N_any_params-1]
if isempty(params)
print(io, string($name), "($vals)")
Expand Down
2 changes: 2 additions & 0 deletions test/test_ProtoStruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ end
const B = :no
const C::T = 3
D
const E::Vector{Int} = Int[]
end

@testset "const fields" begin
cf = @test_nowarn WithConstFields(D = 1.2)
@test cf.A == 1
@test cf.B == :no
@test cf.C == 3
@test_nowarn show(devnull, cf)
cf.A = 5
@test_throws ErrorException cf.B = :yes
@test_throws ErrorException cf.C = 5
Expand Down

0 comments on commit 872efcc

Please sign in to comment.