Skip to content

Commit 82ba8ee

Browse files
ChrisRackauckas-ClaudeChrisRackauckasclaude
committed
Fix invalid setfield! fallback in MOIOptimizationNLPCache setproperty!
`MOIOptimizationNLPCache` is an immutable struct whose `setproperty!` delegates mutation to the (mutable) evaluator and its `ReInitCache`. The final fallback called `setfield!(cache, name, x)` on the immutable cache itself, which can never succeed and which JET flagged as a guaranteed error (`setfield!: immutable struct ... cannot be changed`). Replace the dead fallback with an explicit, informative `ArgumentError`. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RtJAi7bALH5XkakjS6Yb6j
1 parent a674f2f commit 82ba8ee

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/OptimizationMOI/src/nlp.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function Base.setproperty!(cache::MOIOptimizationNLPCache{E}, name::Symbol, x) w
4848
elseif name in fieldnames(OptimizationBase.ReInitCache)
4949
return setfield!(cache.evaluator.reinit_cache, name, x)
5050
end
51-
return setfield!(cache, name, x)
51+
# The cache itself is immutable; its own fields delegate reads through
52+
# `getproperty` but are never reassigned, so there is no valid setter.
53+
throw(ArgumentError(lazy"field `$name` of `MOIOptimizationNLPCache` is immutable and cannot be set"))
5254
end
5355

5456
function SciMLBase.get_p(

0 commit comments

Comments
 (0)