Skip to content

Fix invalid setfield! fallback in MOIOptimizationNLPCache setproperty!#1236

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-moinlpcache-setproperty
Jun 26, 2026
Merged

Fix invalid setfield! fallback in MOIOptimizationNLPCache setproperty!#1236
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-moinlpcache-setproperty

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Summary

MOIOptimizationNLPCache is an immutable struct whose custom 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 (report_package) flags as a guaranteed error:

setproperty!(cache::MOIOptimizationNLPCache{E}, name::Symbol, x::Any) @ nlp.jl:51
  setfield!: immutable struct of type MOIOptimizationNLPCache{E} cannot be changed

This replaces the dead fallback with an explicit, informative ArgumentError. Functionally equivalent (both error), but it makes the intent clear and removes the JET finding.

Testing

Verified with JET.test_package(OptimizationMOI; target_defined_modules = true) locally on Julia 1.12.6: the setproperty!/setfield! finding is gone.

Relationship to #1235

The OptimizationMOI QA (Aqua + JET) job is red on master for three independent reasons. #1235 fixes the two Aqua findings (allowed-piracy declaration + missing ReverseDiff compat) and the cache.verbose JET finding; this PR fixes the remaining setproperty! JET finding. I confirmed locally that with both PRs applied, JET.test_package passes cleanly (0 errors) and Aqua passes 11/11 — i.e. the two together turn the QA job green. Neither is individually sufficient.


This PR is a draft and should be ignored until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RtJAi7bALH5XkakjS6Yb6j

`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
@ChrisRackauckas ChrisRackauckas marked this pull request as ready for review June 26, 2026 09:00
@ChrisRackauckas ChrisRackauckas merged commit f48a07c into SciML:master Jun 26, 2026
36 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants