fix(compiler2): widen empty-collection branches in control-flow joins (B-236)#3781
fix(compiler2): widen empty-collection branches in control-flow joins (B-236)#3781codeshaunted wants to merge 2 commits into
Conversation
… (B-236)
The actual B-236 repro: `let top = if c { xs } else { [] }; top.join(" ")` joined
`string[]` with the empty-array `never[]` to the union `string[] | never[]`.
Method dispatch on a list-union resolves array methods (`.join`) to the map
implementation, so the VM aborts at runtime with `expected map, got array`.
`join_types` now recurses into matching container constructors — `List + List ->
List<join(elem)>`, `Map + Map -> Map<join(k), join(v)>` — so two list (or two map)
branches widen element-wise to a single container instead of a union. An empty
`[]` / `{}` has `never` element/key/value types, which join away, so
`if c { xs } else { [] }` yields `string[]`.
The std library itself hit this (`OrchestrationStep[] | never[]` -> `OrchestrationStep[]`);
TIR and corpus-bytecode snapshots updated accordingly. Adds the runtime repro as a
regression test.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesContainer type join fix (B-236)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
⏭️ Performance benchmarks were skippedPerf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to To run them on this PR, do any of the following, then push a commit (or re-run CI):
|
|
No description provided. |
Follow-up to #3779. That PR fixed several adjacent soundness holes found while investigating B-236, but the actual reported repro still crashed — this PR fixes the real root cause.
The bug
The if/else joined
string[](then) with the empty-arraynever[](else) to the unionstring[] | never[]. A list-union lowers to a non-Listruntime type, so method dispatch resolves array methods (.join) to the map implementation — and the VM aborts when handed an array.The fix
join_typesnow recurses into matching container constructors instead of building a union:List + List → List<join(elem)>Map + Map → Map<join(key), join(value)>An empty
[]/{}hasneverelement/key/value types, which join away, soif c { xs } else { [] }widens tostring[](the issue's own suggested fix). Two list branches of differing element types likewise widen to(a | b)[]rather thana[] | b[].Notes
OrchestrationStep[] | never[]→OrchestrationStep[]) — a latent bug this also fixes. TIR + corpus-bytecode snapshots updated; both diffs are exactlyT[] | never[]→T[]."a b".baml_srccorpus green, fmt + clippy clean.Summary by CodeRabbit