From 872efcc2b91e60fc8fa0d19a9a7bda9ab1770b4b Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 10 Nov 2023 17:47:49 +0900 Subject: [PATCH] Fix `show` for `const` properties of type `Vector` or `Symbol` (#29) * 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 --- src/ProtoStruct.jl | 2 +- test/test_ProtoStruct.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ProtoStruct.jl b/src/ProtoStruct.jl index 0dc16b5..34c959a 100644 --- a/src/ProtoStruct.jl +++ b/src/ProtoStruct.jl @@ -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)") diff --git a/test/test_ProtoStruct.jl b/test/test_ProtoStruct.jl index a532a6d..f1e7a2e 100644 --- a/test/test_ProtoStruct.jl +++ b/test/test_ProtoStruct.jl @@ -153,6 +153,7 @@ end const B = :no const C::T = 3 D + const E::Vector{Int} = Int[] end @testset "const fields" begin @@ -160,6 +161,7 @@ end @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