diff --git a/src/systems/model_parsing.jl b/src/systems/model_parsing.jl index 9d293fd40d..18c1b15922 100644 --- a/src/systems/model_parsing.jl +++ b/src/systems/model_parsing.jl @@ -654,9 +654,9 @@ function parse_model!(exprs, comps, ext, eqs, icon, vs, ps, sps, c_evts, d_evts, elseif mname == Symbol("@defaults") parse_system_defaults!(exprs, arg, dict) elseif mname == Symbol("@constraints") - parse_costs!(cons, dict, body) + parse_constraints!(cons, dict, body) elseif mname == Symbol("@costs") - parse_constraints!(costs, dict, body) + parse_costs!(costs, dict, body) elseif mname == Symbol("@consolidate") parse_consolidate!(body, dict) else @@ -1160,7 +1160,7 @@ function parse_constraints!(cons, dict, body) Base.remove_linenums!(body) for arg in body.args push!(cons, arg) - push!(dict[:constraints], readable_code.(cons)...) + push!(dict[:constraints], readable_code(arg)) end end @@ -1169,7 +1169,7 @@ function parse_costs!(costs, dict, body) Base.remove_linenums!(body) for arg in body.args push!(costs, arg) - push!(dict[:costs], readable_code.(costs)...) + push!(dict[:costs], readable_code(arg)) end end diff --git a/test/model_parsing.jl b/test/model_parsing.jl index fbbca9c7ea..c48628b007 100644 --- a/test/model_parsing.jl +++ b/test/model_parsing.jl @@ -1042,4 +1042,6 @@ end @test isequal(constrs[1], EvalAt(0.3)(ex.x) ~ 3) @test isequal(constrs[2], ex.y ≲ 4) @test ModelingToolkit.get_consolidate(ex)([1, 2], [3, 4]) ≈ 8 + log(2) + @test Example.structure[:constraints] == ["(EvalAt(0.3))(x) ~ 3", "y ≲ 4"] + @test Example.structure[:costs] == ["x + y", "(EvalAt(1))(y) ^ 2"] end