Skip to content

Fix matching on lists and maps by element type#3933

Merged
2kai2kai2 merged 7 commits into
canaryfrom
kai/fix-istype
Jul 7, 2026
Merged

Fix matching on lists and maps by element type#3933
2kai2kai2 merged 7 commits into
canaryfrom
kai/fix-istype

Conversation

@2kai2kai2

@2kai2kai2 2kai2kai2 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator
  • TyTemplate is now generated/convertible via the type family macro
  • Pattern matching on lists and maps will now correctly discriminate on element types instead of always using type tag. The type tag optimization still remains if the compiler can prove there will never be ambiguity (e.g. there is only one type of array in a union)
  • While Self was already rejected in many positions (i.e. most non-interface-related positions) we now give a nice compiler error for it. At a later date, we should allow Self in more places.
  • Object::BoundMethod now correctly holds type args (both from the bound receiver and the function's generics). This ensures we can actually get the type off the value.

Summary by CodeRabbit

  • New Features

    • Expanded match/is type discrimination across containers (lists/maps), unions, classes, enums, and generic type arguments.
    • Improved runtime template-based type checks for more accurate branching.
  • Bug Fixes

    • Fixed incorrect branch selection in container and generic type matches, including enum discrimination and switch/jump-table edge cases.
    • Prevented unsupported Self usage in method body type positions; it now reports clearer compile errors instead of falling back.
  • Tests

    • Added and updated end-to-end and unit coverage for match/is discrimination and Self diagnostics.

2kai2kai2 added 6 commits July 7, 2026 11:40
This prevents drift and allows zero-cost conversions with `RealizedTy`.
TODO: `Self` is currently not properly mapped into TemplateTy
We now emit type-aware code for matching on lists and maps:
- If there is only one map type/list type possible, then we match on
  type tag (any value must have the expected element type)
- Otherwise if there are multiple then we have to emit code to check the
  element types
This hardens the preexisting behavior so it either works or gives a
compiler error instead of unexpected runtime failures. At a later date
([B-687](https://linear.app/boundaryml2/issue/B-687/support-self-everywhere-like-rust))
we should expand support beyond the current narrow usage.
`BoundMethod` should carry its type args. Previously we extracted class
generic args off the receiver, but this is insufficient as it silently
dropped the method's generic args. We now produce the full type arg
frame when the bound method is created, similar to `GenericFunction`
(the function-as-value object)
TODO: actually use the type args
@vercel

vercel Bot commented Jul 7, 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 7, 2026 10:28pm
promptfiddle Ready Ready Preview, Comment Jul 7, 2026 10:28pm
promptfiddle2 Ready Ready Preview, Comment Jul 7, 2026 10:28pm

Request Review

@github-actions

github-actions Bot commented Jul 7, 2026

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 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 25254b7e-7806-4ac2-9eb3-61adef5a04e7

📥 Commits

Reviewing files that changed from the base of the PR and between d4ece3a and af33397.

⛔ Files ignored due to path filters (8)
  • baml_language/crates/baml_tests/snapshots/baml_src/_root.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_alias.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/match_enum_types.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/toml.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__06_codegen.snap is excluded by !**/*.snap
📒 Files selected for processing (10)
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_tests/baml_src/ns_match_enum_types/match_enum_types.baml
  • baml_language/crates/baml_tests/baml_src/ns_toml/toml.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/template.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
🚧 Files skipped from review as they are similar to previous changes (10)
  • baml_language/crates/baml_tests/baml_src/ns_toml/toml.baml
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_tests/baml_src/ns_match_enum_types/match_enum_types.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/baml_type/src/template.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/bex_vm/src/vm.rs

📝 Walkthrough

Walkthrough

This PR separates template-only type handling from realized/runtime types, rewrites MIR/emit/VM template matching around TyTemplate and RealizedTy, and adds a diagnostic that rejects Self in body-position type uses. It also updates tests and supporting helpers to the new type construction and matching paths.

Changes

TyTemplate/RealizedTy Runtime Type Refactor

Layer / File(s) Summary
Type family and template core
baml_language/crates/baml_base/src/attr.rs, baml_language/crates/baml_type/src/family.rs, baml_language/crates/baml_type/src/lib.rs, baml_language/crates/baml_type/src/realized_ty.rs, baml_language/crates/baml_type/src/template.rs, baml_language/crates/baml_type_macros/src/emit.rs, baml_language/crates/baml_type_macros/src/parse.rs
Adds TyAttr::EMPTY, introduces template/projection family axes, adds RealizedTy constructors and display, reworks TyTemplate construction/substitution/display, and updates macro-generated attr handling for attr-less variants.
MIR template lowering and match gating
baml_language/crates/baml_compiler2_mir/src/ir.rs, baml_language/crates/baml_compiler2_mir/src/lower.rs
Updates MIR template lowering to preserve symbolic structure, builds structured dispatch guards, and adds scrutinee-aware tag sufficiency plus backstop handling for refutable match arms.
Emitter and runtime template matching
baml_language/crates/baml_compiler2_emit/src/*, baml_language/crates/bex_engine/src/conversion.rs, baml_language/crates/bex_heap/src/*
Migrates emitter and supporting helpers/tests to TyTemplate::from(RealizedTy::...), rewrites is_type, and expands template traversal for container/composite forms.
VM structural matching and bound-method currying
baml_language/crates/bex_vm/src/*, baml_language/crates/bex_vm/tests/*
Adds VM-side structural template matching, realized-type reconstruction, IsType/LoadType handling, and bound-method receiver type-argument currying, with updated VM tests.
BAML match-discrimination tests
baml_language/crates/baml_tests/baml_src/ns_*/*
Adds end-to-end BAML coverage for container invariance, enum/typevar discrimination, and updated TOML array typing.

Self-in-Body-Position Diagnostic

Layer / File(s) Summary
Diagnostic variant and Self span detection
baml_language/crates/baml_compiler2_tir/src/infer_context.rs, baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
Adds SelfInBodyPosition and a recursive span finder for Self inside type expressions.
Builder enforcement and LSP mapping
baml_language/crates/baml_compiler2_tir/src/builder.rs, baml_language/crates/baml_lsp2_actions/src/check.rs
Reports SelfInBodyPosition during lowering of type expressions, generic arguments, and pattern type tests, and maps it to UnknownType.
Self diagnostic tests
baml_language/crates/baml_tests/projects/diagnostic_errors/self_in_body/main.baml, baml_language/crates/baml_tests/baml_src/ns_match_self_workaround/*
Adds a failing diagnostic project and a workaround test module for explicit enclosing-type naming.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • BoundaryML/baml#3460: Shares the TyTemplate/IsType runtime matching plumbing updated here.
  • BoundaryML/baml#3750: Also changes TyTemplate handling for realized/runtime type construction and matching.
  • BoundaryML/baml#3902: Also adjusts MIR pattern and is/match lowering around generic dispatch guards.

Suggested reviewers: imalsogreg

Poem

A rabbit hopped through type-space bright,
With RealizedTy gleaming just right.
Self in a body? The burrow says no,
And match arms now hop where the true shapes go. 🐇

🚥 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 clearly captures the main change: list and map matching now discriminates by element type.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch kai/fix-istype

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.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 21.7 MB 9.3 MB file 21.5 MB +207.9 KB (+1.0%) OK
packed-program Linux 🔒 15.9 MB 6.7 MB file 15.6 MB +258.2 KB (+1.7%) OK
baml-cli macOS 🔒 16.7 MB 8.1 MB file 16.6 MB +182.2 KB (+1.1%) OK
packed-program macOS 🔒 12.3 MB 5.8 MB file 12.1 MB +198.9 KB (+1.6%) OK
baml-cli Windows 🔒 18.3 MB 8.3 MB file 18.1 MB +167.9 KB (+0.9%) OK
packed-program Windows 🔒 13.2 MB 5.9 MB file 13.0 MB +203.4 KB (+1.6%) OK
bridge_wasm WASM 14.6 MB 🔒 4.1 MB gzip 4.1 MB +88.6 KB (+2.2%) 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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
baml_language/crates/baml_compiler2_mir/src/lower.rs (1)

15553-15600: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve associated-type projections in the dispatch-guard template

Lowering AssociatedTypeProjection to Wildcard lets patterns like Foo<T.Assoc> or Iface<Err = T.CompareError> match unrelated values. Keep the projection leaf intact here, or fail closed until projection-aware matching exists.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/baml_compiler2_mir/src/lower.rs` around lines 15553 -
15600, The dispatch-guard lowering in tir2_to_dispatch_guard_template currently
drops AssociatedTypeProjection by turning it into Wildcard, which makes patterns
like Foo<T.Assoc> or Iface<Err = T.CompareError> over-match unrelated values.
Update the template-building path used by emit_is_type_template_branch so
AssociatedTypeProjection stays preserved as a real leaf, or otherwise fail
closed in this branch until projection-aware matching is implemented; keep the
change localized around tir2_to_dispatch_guard_template and the contains_typevar
gating in lower.rs.
baml_language/crates/bex_vm/src/package_baml/resolve.rs (1)

401-420: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Require interface associated bindings to match both ways.

Lines 415-420 only validate bindings that already exist on the concrete side. That lets a symbolic pattern like Pair<Iterable<Item=T>, T> match Pair<Iterable, int> once T is bound by the second slot, even though the interface argument never proves Item = int. baml_type::Interface::to_ty explicitly allows partial associated-type bindings, so the matcher cannot assume the two binding sets coincide.

Proposed fix
         TyTemplate::Interface(name, args, assoc, _) => match concrete {
             RuntimeTy::Interface(cname, cargs, cassoc, _) => {
-                // Each *concrete* binding must match a same-named pattern binding, found
-                // order-insensitively; extra pattern bindings don't constrain. This
-                // direction mirrors the compiler's selection matcher
-                // (`match_ty_pattern_into`'s `Interface` arm, which iterates the concrete
-                // bindings and requires each in the pattern) so runtime dispatch never
-                // selects an impl compile-time selection would reject. A positional,
-                // length-locked `zip` would instead diverge if the two declaration orders
-                // differed. (A top-level interface for-type is rejected by
-                // `is_valid_impl_subject`; this is only reached for a nested interface
-                // argument, where the binding sets coincide in well-formed code.)
+                // Match associated bindings by name, but require the same binding set on
+                // both sides. Partial interface existentials are valid runtime types.
                 name == cname
                     && all_match(args, cargs, bindings)
-                    && cassoc.iter().all(|(cn, ct)| {
-                        assoc
-                            .iter()
-                            .find(|(an, _)| an == cn)
-                            .is_some_and(|(_, at)| match_template(at, ct, bindings))
-                    })
+                    && cassoc.len() == assoc.len()
+                    && assoc.iter().all(|(an, at)| {
+                        cassoc
+                            .iter()
+                            .find(|(cn, _)| cn == an)
+                            .is_some_and(|(_, ct)| match_template(at, ct, bindings))
+                    })
             }
             _ => false,
         },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@baml_language/crates/bex_vm/src/package_baml/resolve.rs` around lines 401 -
420, The TyTemplate::Interface matcher only checks associated bindings from the
concrete RuntimeTy::Interface side, so a pattern can match without proving the
pattern’s own associated bindings are satisfied. Update match_template in the
TyTemplate::Interface arm to validate associated bindings in both directions:
keep the existing concrete-to-pattern check and also ensure every associated
binding in the pattern exists on the concrete side and matches via
match_template, using the same binding lookup logic as all_match. This should be
applied alongside the existing name == cname and all_match(args, cargs,
bindings) checks so interface matching is symmetric for associated types.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/baml_compiler2_mir/src/lower.rs`:
- Around line 1320-1369: The new tag-sufficiency gate in
switch_member_tag_sufficient still treats RuntimeTy::Enum and
RuntimeTy::EnumVariant as always safe, but type_tag_for_ty() maps them to the
shared ENUM tag so different enum values can still collide. Update
switch_member_tag_sufficient to fail closed for enum-related members, causing
the switch lowering path to fall back to the precise chain until a
per-enum/per-variant sufficiency proof exists. Use the existing
RuntimeTy::Class, RuntimeTy::List, and RuntimeTy::Map handling as the pattern
for where to branch, but make enum cases return false rather than true.

In `@baml_language/crates/bex_vm/src/package_baml/resolve.rs`:
- Around line 440-446: The symbolic function-matching path in resolve.rs is too
permissive compared with ty_equivalent because it ignores parameter names while
comparing params in the fast path. Update the matching logic in the affected arm
to also require the parameter names to match, alongside mode and type, so
symbolic signatures behave consistently with the realized path used by
ty_equivalent. Use the existing param comparison in the function
pattern-matching code as the place to align this behavior.

---

Outside diff comments:
In `@baml_language/crates/baml_compiler2_mir/src/lower.rs`:
- Around line 15553-15600: The dispatch-guard lowering in
tir2_to_dispatch_guard_template currently drops AssociatedTypeProjection by
turning it into Wildcard, which makes patterns like Foo<T.Assoc> or Iface<Err =
T.CompareError> over-match unrelated values. Update the template-building path
used by emit_is_type_template_branch so AssociatedTypeProjection stays preserved
as a real leaf, or otherwise fail closed in this branch until projection-aware
matching is implemented; keep the change localized around
tir2_to_dispatch_guard_template and the contains_typevar gating in lower.rs.

In `@baml_language/crates/bex_vm/src/package_baml/resolve.rs`:
- Around line 401-420: The TyTemplate::Interface matcher only checks associated
bindings from the concrete RuntimeTy::Interface side, so a pattern can match
without proving the pattern’s own associated bindings are satisfied. Update
match_template in the TyTemplate::Interface arm to validate associated bindings
in both directions: keep the existing concrete-to-pattern check and also ensure
every associated binding in the pattern exists on the concrete side and matches
via match_template, using the same binding lookup logic as all_match. This
should be applied alongside the existing name == cname and all_match(args,
cargs, bindings) checks so interface matching is symmetric for associated types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ccbbf8e4-e7ff-44d6-94eb-24a677fcfc40

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1b97e and 5971729.

⛔ Files ignored due to path filters (29)
  • baml_language/crates/baml_tests/snapshots/baml_src/_root.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/csv.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_subtype.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_match_typevar.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/inferred_generic_type_args.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/iter_impl_generics_only.core.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_alias.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_parse_stringify.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_to_from_string.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/match_container_types.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/match_self_workaround.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/patterns_new_runtime.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/toml.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiler2_mir/baml_tests__compiler2_mir__match_or_mixed_array_class_binding_uses_branch_local_rest_type.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/llm_image_outputs/baml_tests__compiles__llm_image_outputs__06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/patterns_new/baml_tests__compiles__patterns_new__06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__01_lexer__main.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__02_parser__main.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__03_hir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__04_tir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__05_diagnostics.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/diagnostic_errors/self_in_body/baml_tests__diagnostic_errors__self_in_body__10_formatter__main.snap is excluded by !**/*.snap
📒 Files selected for processing (38)
  • baml_language/crates/baml_base/src/attr.rs
  • baml_language/crates/baml_compiler2_emit/src/analysis.rs
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_emit/src/lib.rs
  • baml_language/crates/baml_compiler2_emit/src/pull_semantics.rs
  • baml_language/crates/baml_compiler2_emit/src/stack_carry.rs
  • baml_language/crates/baml_compiler2_mir/src/ir.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_compiler2_tir/src/infer_context.rs
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_lsp2_actions/src/check.rs
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_subtype/generic_match_subtype.baml
  • baml_language/crates/baml_tests/baml_src/ns_generic_match_typevar/generic_match_typevar.baml
  • baml_language/crates/baml_tests/baml_src/ns_match_container_types/match_container_types.baml
  • baml_language/crates/baml_tests/baml_src/ns_match_self_workaround/match_self_workaround.baml
  • baml_language/crates/baml_tests/baml_src/ns_toml/toml.baml
  • baml_language/crates/baml_tests/projects/diagnostic_errors/self_in_body/main.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/lib.rs
  • baml_language/crates/baml_type/src/realized_ty.rs
  • baml_language/crates/baml_type/src/template.rs
  • baml_language/crates/baml_type_macros/src/emit.rs
  • baml_language/crates/baml_type_macros/src/parse.rs
  • baml_language/crates/bex_engine/src/conversion.rs
  • baml_language/crates/bex_heap/src/gc.rs
  • baml_language/crates/bex_heap/src/tlab.rs
  • baml_language/crates/bex_vm/src/lib.rs
  • baml_language/crates/bex_vm/src/package_baml/mod.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/type_context.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/bex_vm/tests/interface_registry.rs
  • baml_language/crates/bex_vm/tests/load_type.rs
  • baml_language/crates/bex_vm/tests/method_class_type_args.rs
  • baml_language/crates/bex_vm_types/src/types/class.rs
  • baml_language/crates/bex_vm_types/src/types/function.rs
💤 Files with no reviewable changes (1)
  • baml_language/crates/baml_type/src/lib.rs
👮 Files not reviewed due to content moderation or server errors (4)
  • baml_language/crates/baml_compiler2_tir/src/infer_context.rs
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_compiler2_tir/src/builder.rs
  • baml_language/crates/baml_lsp2_actions/src/check.rs

Comment thread baml_language/crates/baml_compiler2_mir/src/lower.rs
Comment thread baml_language/crates/bex_vm/src/package_baml/resolve.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@baml_language/crates/baml_compiler2_mir/src/lower.rs`:
- Around line 1354-1366: The `RuntimeTy::Enum` branch in `lower.rs` is too
permissive because `flat.iter().all(...)` currently treats `None` from
`enum_type_name` as safe; update this logic to fail closed for opaque members,
matching the container branch behavior. In the
`flatten_runtime_union`/`enum_type_name` check, reject any member that does not
resolve to the same enum name as the `name` being matched so `TypeTag` safety
does not rely on shared `ENUM` tags across different enums.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f4c9891-b669-4e55-9894-03140f842b02

📥 Commits

Reviewing files that changed from the base of the PR and between 5971729 and d4ece3a.

⛔ Files ignored due to path filters (8)
  • baml_language/crates/baml_tests/snapshots/baml_src/_root.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_alias.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/match_enum_types.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/toml.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/__baml_std__/baml_tests__compiles____baml_std____06_codegen.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__04_5_mir.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/compiles/json_alias_basic/baml_tests__compiles__json_alias_basic__06_codegen.snap is excluded by !**/*.snap
📒 Files selected for processing (10)
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_compiler2_mir/src/lower.rs
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_tests/baml_src/ns_match_enum_types/match_enum_types.baml
  • baml_language/crates/baml_tests/baml_src/ns_toml/toml.baml
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/baml_type/src/template.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/vm.rs
🚧 Files skipped from review as they are similar to previous changes (8)
  • baml_language/crates/baml_compiler2_tir/src/lower_type_expr.rs
  • baml_language/crates/baml_tests/baml_src/ns_toml/toml.baml
  • baml_language/crates/bex_vm/src/type_match.rs
  • baml_language/crates/bex_vm/src/package_baml/resolve.rs
  • baml_language/crates/baml_compiler2_emit/src/emit.rs
  • baml_language/crates/baml_type/src/family.rs
  • baml_language/crates/bex_vm/src/vm.rs
  • baml_language/crates/baml_type/src/template.rs

Comment thread baml_language/crates/baml_compiler2_mir/src/lower.rs
@2kai2kai2
2kai2kai2 added this pull request to the merge queue Jul 7, 2026
Merged via the queue into canary with commit 8afbddd Jul 7, 2026
53 checks passed
@2kai2kai2
2kai2kai2 deleted the kai/fix-istype branch July 7, 2026 22:48
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