Skip to content

Add begin/rescue/ensure exception handling support#48

Merged
dak2 merged 1 commit into
mainfrom
add-exception-handling-support
Mar 8, 2026
Merged

Add begin/rescue/ensure exception handling support#48
dak2 merged 1 commit into
mainfrom
add-exception-handling-support

Conversation

@dak2

@dak2 dak2 commented Mar 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add type inference for begin/rescue/else/ensure blocks and inline rescue modifier
  • Rescue chains are processed recursively with Union type aggregation (same pattern as conditionals)
  • Rescue variable (=> e) is scoped to the rescue block with save/restore semantics
  • else clause replaces begin body type per Ruby spec; ensure is side-effect only
  • Empty rescue body evaluates to nil

Test plan

  • 15 Rust unit tests in exceptions.rs covering all branch combinations
  • 2 LocalEnv::remove_var unit tests
  • 5 Ruby integration tests (type inference + CLI check for false positives and error detection)
  • Run cd rust && cargo test --lib to verify all Rust tests pass
  • Run bundle exec rake test to verify all Ruby integration tests pass

🤖 Generated with Claude Code

Implement type inference for Ruby's exception handling constructs
(begin/rescue/else/ensure and inline rescue modifier) following the
Union type pattern established in conditionals.rs.

Key design decisions:
- rescue chains are processed recursively (consistent with elsif)
- rescue variable (=> e) is scoped to the rescue block (save/restore)
- else clause replaces begin body type (Ruby spec compliance)
- ensure clause is side-effect only, does not affect return type
- Empty rescue body evaluates to nil
- Exception variable defaults to StandardError type

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dak2 dak2 merged commit c1ed2af into main Mar 8, 2026
2 checks passed
@dak2 dak2 deleted the add-exception-handling-support branch March 8, 2026 04:47
@dak2 dak2 mentioned this pull request Mar 9, 2026
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.

1 participant