Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

  • Add JET.jl as a test dependency for static analysis testing
  • Add JET static analysis test to qa.jl that verifies the Optimization module has no JET-detectable errors
  • Fix several type instability issues found during JET analysis

Changes

Bug Fixes

  1. filled_spad in adtypes.jl: Added missing else clause that caused implicit nothing return when both sparsity_detector and coloring_algorithm were already set. This could cause downstream type instabilities.

  2. __solve(cache::AbstractOptimizationCache) in solve.jl: Replaced empty function body with proper ArgumentError throw. The previous implementation returned nothing implicitly which violated the return type annotation and caused JET to report a type conversion error.

  3. instantiate_function error path in function.jl: Fixed handling of edge case where both findfirst('(', ...) and findfirst('{', ...) return nothing, which would cause nothing - 1 to fail at runtime.

New Tests

  • Added JET.jl static analysis test to test/qa.jl that runs JET.report_package on the Optimization module and asserts zero errors

JET Analysis Results

After these fixes:

  • Optimization module: 0 JET errors ✓
  • OptimizationBase module: 11 errors remaining (all false positives related to conditional variable definitions that JET cannot track statically)

The remaining 11 errors in OptimizationBase are not real bugs - they occur because JET cannot track the relationship between conditional checks for f.cons !== nothing and the definitions of cons_oop/lagrangian variables. At runtime, these code paths are always guarded correctly.

Test Plan

  • JET static analysis passes for Optimization module
  • All existing tests pass
  • Package loads and compiles correctly

cc @ChrisRackauckas

🤖 Generated with Claude Code

- Add JET.jl as a test dependency for static analysis testing
- Add JET static analysis test to qa.jl that verifies the Optimization
  module has no JET-detectable errors
- Fix `filled_spad` in adtypes.jl: add missing else clause that caused
  implicit `nothing` return when both sparsity_detector and
  coloring_algorithm were already set
- Fix `__solve(cache::AbstractOptimizationCache)` in solve.jl: replace
  empty function body with proper error throw to prevent type instability
  from implicit `nothing` return
- Fix `instantiate_function` error path in function.jl: handle case where
  both `findfirst('(', ...)` and `findfirst('{', ...)` return nothing,
  preventing potential runtime error

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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