Skip to content

Commit 3c5b774

Browse files
authored
Fix showing conjugate variables (#288)
* Fix showing conjugate variables * Add test
1 parent 79c141e commit 3c5b774

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Base.show(io::IO, p::TypesWithShow) = show(io, MIME"text/plain"(), p)
2828
function _show(io::IO, mime::MIME, var::AbstractVariable)
2929
base, indices = name_base_indices(var)
3030
if isconj(var)
31-
for c in base
31+
for c in String(base)
3232
print(io, c, '\u0305') # displays as overbar (̄z)
3333
end
3434
else

test/complex.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
ordinary_variable(real(x)) ==
2626
ordinary_variable(imag(x)) ==
2727
ordinary_variable(x)
28+
@testset "show" begin
29+
struct SymbolVar <: MP.AbstractVariable end
30+
struct SymbolConjVar <: MP.AbstractVariable end
31+
Base.isreal(::Union{SymbolVar,SymbolConjVar}) = false
32+
MP.name_base_indices(::Union{SymbolVar,SymbolConjVar}) = (:xy, (1, 2))
33+
MP.isconj(::SymbolConjVar) = true
34+
@test sprint(show, SymbolVar()) == "xy₁₋₂"
35+
@test sprint(show, SymbolConjVar()) == "x̅y̅₁₋₂"
36+
end
2837
@test conj(x) != x && conj(conj(x)) == x
2938
@test real(x) == real(conj(x))
3039
@test imag(conj(x)) == -imag(x)

0 commit comments

Comments
 (0)