Skip to content

fix(compiler): unify empty-array catch arms with try-block element type - #4210

Closed
antoniosarosi wants to merge 2 commits into
canaryfrom
antoniosarosi/b-616
Closed

antoniosarosi wants to merge 2 commits into
canaryfrom
antoniosarosi/b-616

Conversation

@antoniosarosi

@antoniosarosi antoniosarosi commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes B-616

Use the try-block type as a soft expectation for synthesized catch arms so compatible empty and nested container literals adopt it without rejecting genuinely different union members.

Tests cover for-in, direct and let-bound use, nested and non-empty array literals, empty maps, and heterogeneous catch results.

Summary by CodeRabbit

  • Bug Fixes

    • Improved type inference for catch expressions, including empty and nested arrays, maps, and object literals.
    • Catch results now correctly support downstream operations such as iteration and length checks.
    • Incompatible catch-arm types now produce an appropriate union type instead of an erroneous mismatch.
  • Tests

    • Added coverage for catch-all result type synthesis and nested container inference.

@linear

linear Bot commented Jul 26, 2026

Copy link
Copy Markdown

B-616

@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 26, 2026 2:22pm
promptfiddle Ready Ready Preview, Comment Jul 26, 2026 2:22pm
promptfiddle2 Ready Ready Preview, Comment Jul 26, 2026 2:22pm

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_tir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/catch_throw/baml_tests__compiles__catch_throw__04_tir.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 42a8771b-12ad-4719-a082-e29353b749e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Catch-arm inference now treats the try-block type as a soft contextual expectation, recursively adopting compatible container literal types while preserving unions for incompatible fallbacks. New Phase 8 tests cover arrays, maps, nested containers, and downstream resolution.

Changes

Catch-arm inference

Layer / File(s) Summary
Contextual catch-arm inference
baml_language/crates/baml_compiler2_tir/src/builder.rs
Catch-arm synthesis can contextually adopt compatible try-block container types through transactional recursive updates, while retaining union behavior for incompatible expressions.
Catch-arm synthesis validation
baml_language/crates/baml_tests/src/compiler2_tir/phase8_exceptions.rs
Tests cover empty and nested arrays, maps, downstream iteration and length resolution, compatible literals, and incompatible fallback unions.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CatchAll
  participant CatchArmInference
  participant ContextualUpdates
  participant TIR
  CatchAll->>CatchArmInference: infer fallback expression
  CatchArmInference->>ContextualUpdates: compare with try-block base type
  ContextualUpdates-->>CatchArmInference: apply recursive updates or roll back
  CatchArmInference->>TIR: synthesize adopted type or union
Loading

Possibly related PRs

Suggested reviewers: codeshaunted, aaronvg, rossirpaulo

Poem

I’m a rabbit refining types in the hay,
Empty arrays find their shape today.
Maps hop neatly into place,
Unions keep mismatches safe in space.
Tests nibble errors away—
Thump, compile, and all is okay!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: catch-arm inference now softly adopts the try-block type for empty arrays and related container literals.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch antoniosarosi/b-616

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel
vercel Bot temporarily deployed to Preview – beps July 26, 2026 13:50 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 26, 2026 13:58 Inactive
@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 27.2 MB 11.6 MB file 27.1 MB +153.7 KB (+0.6%) OK
✅ packed-program Linux 🔒 17.7 MB 7.3 MB file 17.6 MB +11.3 KB (+0.1%) OK
✅ baml-cli macOS 🔒 21.2 MB 10.1 MB file 21.0 MB +149.1 KB (+0.7%) OK
✅ packed-program macOS 🔒 13.8 MB 6.4 MB file 13.8 MB +33.1 KB (+0.2%) OK
✅ baml-cli Windows 🔒 22.8 MB 10.3 MB file 22.7 MB +128.5 KB (+0.6%) OK
✅ packed-program Windows 🔒 14.7 MB 6.5 MB file 14.7 MB +6.7 KB (+0.0%) OK
✅ bridge_wasm WASM 16.5 MB 🔒 4.5 MB gzip 4.5 MB +19.8 KB (+0.4%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@vercel
vercel Bot temporarily deployed to Preview – beps July 26, 2026 14:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 26, 2026 14:08 Inactive
@antoniosarosi

Copy link
Copy Markdown
Contributor Author

Closing — this was an orchestration experiment run; not landing.

@antoniosarosi
antoniosarosi deleted the antoniosarosi/b-616 branch July 26, 2026 14:15
@vercel
vercel Bot temporarily deployed to Preview – promptfiddle July 26, 2026 14:22 Inactive

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — e285cfc1 Deployed Jul 26, 2026 by vercel[bot]
Preview – promptfiddle2 — e285cfc1 Deployed Jul 26, 2026 by vercel[bot]
Preview – beps — e285cfc1 Deployed Jul 26, 2026 by vercel[bot]
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