From 82ba8ee8f97e1c724a81e10f3fbdb2674398ccc3 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Thu, 25 Jun 2026 05:45:43 -0400 Subject: [PATCH] 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 Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01RtJAi7bALH5XkakjS6Yb6j --- lib/OptimizationMOI/src/nlp.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OptimizationMOI/src/nlp.jl b/lib/OptimizationMOI/src/nlp.jl index 87d7bc97c..53572c9bd 100644 --- a/lib/OptimizationMOI/src/nlp.jl +++ b/lib/OptimizationMOI/src/nlp.jl @@ -48,7 +48,9 @@ function Base.setproperty!(cache::MOIOptimizationNLPCache{E}, name::Symbol, x) w elseif name in fieldnames(OptimizationBase.ReInitCache) return setfield!(cache.evaluator.reinit_cache, name, x) end - return setfield!(cache, name, x) + # The cache itself is immutable; its own fields delegate reads through + # `getproperty` but are never reassigned, so there is no valid setter. + throw(ArgumentError(lazy"field `$name` of `MOIOptimizationNLPCache` is immutable and cannot be set")) end function SciMLBase.get_p(