fix(parser): reject constraint bounds that depend on v/x/u/t (#343) - #345
Merged
ocots merged 2 commits intoAug 31, 2026
Merged
Conversation
A boundary/path constraint whose bound referenced the optimization variable (e.g. `x₂(0) == v`) failed with a leaked internal gensym `UndefVarError: v##NNNN` instead of a clear error, because `lb`/`ub` are evaluated once at build time and cannot see a function-argument name. `p_constraint!` now checks both bounds and returns a `ParsingError` pointing to the fix (`x₂(0) - v == 0`). Backend-agnostic: covers both `:fun` and `:exa`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This was referenced Aug 31, 2026
This was referenced Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #343.
Stacked on #326 — this PR targets
chore/deps-examodels-0.12so it can be reviewed and adjusted independently.Problem
A boundary constraint whose bound references the optimization variable, e.g.
x₂(0) == v, was correctly rejected but with an internal gensym leaking into the message:Root cause: in
parse!aliases are substituted first, sovbecomesv##NNNN[1].x₂(0) == vcallsp_constraint!(p, p_ocp, e2, e1, e2)— the boundse1/e3arev##NNNN[1]— andp_constraint_fun!emitsconstraint!(ocp, :boundary; f=fun, lb=(v##NNNN[1]), ub=(v##NNNN[1]), …).lb/ubare evaluated once at build time, but the gensym is only a function-argument name (for the:funbackend it is never bound at all), hence theUndefVarError.p_constraint!never validated the bounds.This matches the documented rule "constraint bounds must be effective, that is must not depend on a variable".
Change
p_constraint!now checks both bounds and, if either depends onv, the state, the control or the time, returns aCTBase.ParsingErrornaming the real cause:The check is backend-agnostic (before the
:fun/:exadispatch), sov == x₂(0)andx₁(0) ≤ x₂(0)are caught too. The constrained side may still reference the variable (e.g.0 ≤ r(0) - z ≤ 1) — only the bounds are restricted.Public API
No change. An input that used to throw
UndefVarErrornow throwsCTBase.ParsingError; nothing that used to build changes.Tests
test/test_onepass_fun.jl: two@test_throws ParsingErrorcases plus a positive check that the documented work-aroundx₂(0) - v == 0still builds.test/test_onepass_exa.jl: one matching@test_throws ParsingErrorfor the:exapath.🤖 Generated with Claude Code