Skip to content

[Beam] Fix try/catch warnings and reraise unbound variable bug#4392

Open
dbrattli wants to merge 3 commits intomainfrom
dbrattli/beam-improvements-17
Open

[Beam] Fix try/catch warnings and reraise unbound variable bug#4392
dbrattli wants to merge 3 commits intomainfrom
dbrattli/beam-improvements-17

Conversation

@dbrattli
Copy link
Collaborator

Summary

  • Fix unused term warning in try/catch: Skip exception wrapping (#{message => ...}) in catch blocks that don't reference the exception variable, using containsIdentRef to check usage
  • Fix "no effect" warning: Extend stripStrayOkstripNoEffect to also strip literals, standalone variables, and pure BIF calls (self/0, node/0) from non-final block positions
  • Fix reraise() generating unbound MatchValue variable: Add CatchReasonVar to the Beam context so Throw emits erlang:error(Exn_reason_N) directly using the raw Erlang reason variable. This fixes seq.erl compilation failures where reraise() in catch blocks produced references to never-bound variables
  • Fix containsIdentRef / isCapturedInClosure: Add missing Extended(Throw(...)) case so reraise references to catch variables are properly detected

Test plan

  • All 2264 Beam tests pass (4 new tests added)
  • seq.erl now compiles without unbound variable errors
  • New tests cover: wildcard catch without exception usage, reraise preserving exception, reraise with side effects, try/catch result used in pattern match

🤖 Generated with Claude Code

dbrattli and others added 3 commits March 11, 2026 06:54
- Skip exception wrapping (#{message => ...}) in catch blocks that don't
  reference the exception variable, eliminating unused term warnings
- Strip side-effect-free expressions (literals, variables, pure BIFs like
  self/0, node/0) from non-final block positions to avoid "no effect" warnings
- Fix reraise() generating unbound MatchValue variable by adding
  CatchReasonVar to context so Throw uses the raw Erlang reason variable
- Add Extended case to containsIdentRef/isCapturedInClosure utilities

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fable_utils:to_list already handles binaries (strings) via
unicode:characters_to_list, but Seq.toList was falling through to the
compiled seq:to_list which doesn't handle raw BEAM types. Add explicit
Replacement for Seq.toList to use fable_utils:to_list.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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