Skip to content

fix(hir_ty): diagnose unknown methods on inferred generics - #4534

Open
sxlijin wants to merge 1 commit into
canaryfrom
sxlijin/gh-4506-inferred-generic-unknown-method-ice
Open

fix(hir_ty): diagnose unknown methods on inferred generics#4534
sxlijin wants to merge 1 commit into
canaryfrom
sxlijin/gh-4506-inferred-generic-unknown-method-ice

Conversation

@sxlijin

@sxlijin sxlijin commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Retry call-site member resolution after ordinary lookup misses when nested receiver inference variables already have enough evidence to become concrete.
  • Preserve the noncommittal conditional-impl probe first, so valid generic factory/member calls keep their existing behavior.
  • Add span-aware E0007 regressions for inferred and explicit user-defined generic receivers, inferred stdlib Repeat and ArrayIterator receivers, and a valid inferred generic method control.

Root cause

Probe.new(1) initially produces Probe<?T> while the argument constraint 1 <: ?T is pending. Call member resolution knew the class head but left the nested variable unresolved; after all lookup tiers missed, the has_infer cascade guard suppressed E0007. Finalization later grounded the receiver to Probe<int>, leaving MIR to encounter an impossible unknown field and emit the internal compiler error. The fix commits already-sufficient nested inference evidence at the call-resolution miss point and retries normal lookup, so the existing span-aware E0007 path owns the error before MIR.

Relationship to #4468

This does not share the root cause of #4468. #4468 was fixed by #4490 and involved stale syntactic union/projection canonicalization plus a for-loop inference verdict/report mismatch. #4506 is an earlier member-call diagnostic deferral hole on a structured receiver containing nested inference variables, so this PR remains focused on that invariant.

Validation

  • cargo test -p baml_compiler2_hir_ty --lib
  • cargo test -p baml_tests --lib compiler2_tir
  • Focused inferred, explicit, stdlib, valid-member, and LSP iterator inference controls
  • mise run fmt
  • mise run clippy
  • mise run clippy-wasm
  • cargo insta test --test-runner nextest -p baml_tests -p baml_cli -p baml_lsp2_actions_tests --all-features --unreferenced=reject (2,969 passed; the sole shared-temp generator collision passed when rerun with an isolated TMPDIR)

Fixes #4506

Summary by CodeRabbit

  • Bug Fixes

    • Improved member and method resolution when receiver types are inferred or generic.
    • Missing-method diagnostics now appear reliably once types become concrete.
    • Prevented duplicate diagnostics while preserving valid method resolution.
  • Tests

    • Added coverage for inferred and explicit generic receivers, including standard-library factory results.
    • Verified accurate diagnostic codes, source spans, and missing-member reporting.

@vercel

vercel Bot commented Aug 19, 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 Aug 19, 2026 9:13pm
promptfiddle2 Ready Ready Preview Aug 19, 2026 9:13pm

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 Aug 19, 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 Plus

Run ID: a042a632-681a-4973-9aae-e847b1f32aa7

📥 Commits

Reviewing files that changed from the base of the PR and between 89ee4dc and 88a8000.

📒 Files selected for processing (2)
  • baml_language/crates/baml_compiler2_hir_ty/src/infer.rs
  • baml_language/crates/baml_tests/src/compiler2_tir/inference.rs

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The compiler now retries member resolution after inference variables become concrete. New tests validate E0007 diagnostics for missing methods and successful resolution for inferred generic receivers.

Changes

Inference-aware member resolution

Layer / File(s) Summary
Retry member lookup after inference
baml_language/crates/baml_compiler2_hir_ty/src/infer.rs
Member resolution forces evidence-backed occurring variables and retries lookup when the receiver becomes more concrete.
Validate generic receiver behavior
baml_language/crates/baml_tests/src/compiler2_tir/inference.rs
Tests validate span-aware E0007 diagnostics for missing methods and valid method resolution on inferred generic receivers. A shared helper checks diagnostic count, code, and span.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 88a80

The change is localized and no actionable merge-blocking risk remains beyond completing normal test checks.

Suggested reviewers: antoniosarosi, codeshaunted

Sequence Diagram(s)

sequenceDiagram
  participant InferenceTest
  participant MemberCalleeResolver
  participant DiagnosticReporter
  InferenceTest->>MemberCalleeResolver: Resolve member on generic receiver
  MemberCalleeResolver->>MemberCalleeResolver: Force variables and retry lookup
  MemberCalleeResolver->>DiagnosticReporter: Report E0007 when member is missing
  DiagnosticReporter-->>InferenceTest: Return diagnostic and source span
Loading

Poem

I’m a small rabbit tuning types,
With carrots of evidence in my grips.
Missing hops now raise E0007,
Valid hops land where they’re expected.
One clear span, then tests approve—
The inferred paths now smoothly move.

🚥 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 and concisely describes the change to diagnose unknown methods on inferred generic receivers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 sxlijin/gh-4506-inferred-generic-unknown-method-ice

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

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 31.8 MB 12.6 MB file 31.7 MB +152.9 KB (+0.5%) OK
packed-program Linux 🔒 25.0 MB 9.2 MB file 24.9 MB +176.8 KB (+0.7%) OK
baml-cli macOS 🔒 25.6 MB 11.2 MB file 25.5 MB +81.9 KB (+0.3%) OK
packed-program macOS 🔒 20.8 MB 8.2 MB file 20.6 MB +207.1 KB (+1.0%) OK
baml-cli Windows 🔒 27.3 MB 11.4 MB file 27.2 MB +151.4 KB (+0.6%) OK
packed-program Windows 🔒 21.9 MB 8.3 MB file 21.7 MB +151.5 KB (+0.7%) OK
bridge_wasm WASM 21.4 MB 🔒 5.4 MB gzip 5.3 MB +70.4 KB (+1.3%) 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

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.

[bug] 0.17.0 canary: internal compiler error on unknown method when generic type arguments are inferred

1 participant