diff --git a/src/utilities/show.jl b/src/utilities/show.jl index 35973db81..73cf45528 100644 --- a/src/utilities/show.jl +++ b/src/utilities/show.jl @@ -217,10 +217,16 @@ function TreePrint.print_tree(io::IO, p::Problem, args...; kwargs...) args...; kwargs..., ) - if !isempty(p.constraints) + all_constraints = copy(p.constraints) + for leaf in AbstractTrees.Leaves(p) + if leaf isa AbstractVariable + append!(all_constraints, get_constraints(leaf)) + end + end + if !isempty(all_constraints) TreePrint.print_tree( io, - ProblemConstraintsRoot(p.constraints), + ProblemConstraintsRoot(all_constraints), args...; kwargs..., ) diff --git a/test/test_utilities.jl b/test/test_utilities.jl index da6b4df2a..64edf43a8 100644 --- a/test/test_utilities.jl +++ b/test/test_utilities.jl @@ -1325,6 +1325,16 @@ function test_Constant_complex() return end +function test_show_with_variable_constraints() + x = Variable() + add_constraint!(x, x >= 1) + p = minimize(x) + tree = sprint(show, p) + @test occursin("subject to", tree) + @test occursin("≥ constraint (affine)", tree) + return +end + end # TestUtilities TestUtilities.runtests()