Skip to content

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

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

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
beps Ready Ready Preview Sep 17, 2026 9:11pm UTC
developer-docs Ready Ready Preview Sep 17, 2026 9:11pm UTC
promptfiddle2 Ready Ready Preview Sep 17, 2026 9:11pm UTC

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.

@vercel
vercel Bot temporarily deployed to Preview – beps August 19, 2026 21:06 Inactive
@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 56a0ec13-7f74-4464-87a2-15e4baf20827

📥 Commits

Reviewing files that changed from the base of the PR and between 88a8000 and 6fa415f.

📒 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

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

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

Merge Risk: ⚪ Minimal · up to 88a80

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

🚥 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

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.

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

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 August 19, 2026 21:13 Inactive
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

Binary size checks failed

❌ 1 violations · ✅ 2 passed

⚠️ Please fix the size gate issues or acknowledge them by updating baselines.

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 73.9 MB 27.7 MB file 73.1 MB +805.7 KB (+1.1%) OK
✅ packed-program Linux 🔒 30.0 MB 11.4 MB file 29.2 MB +807.5 KB (+2.8%) OK
❌ bridge_wasm WASM 22.6 MB 🔒 5.8 MB gzip 5.7 MB +174.0 KB (+3.1%) FAIL

🔒 = 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.

Details & how to fix

Violations:

  • bridge_wasm (WASM) gzip_delta_pct: +3.1% exceeds limit of 3.0% (exceeded by +0.1pp, policy: max_delta_pct)

Add/update baselines:

.ci/size-gate/wasm32-unknown-unknown.toml:

[artifacts.bridge_wasm]
file_bytes = 22577517
gzip_bytes = 5836309

Generated by cargo size-gate · workflow run

@ritunjaym

Copy link
Copy Markdown
Contributor

I filed #4506 and tested this branch against the original reproducers.
It resolves all of them.

Built sxlijin/gh-4506-inferred-generic-unknown-method-ice at 88a80007
and re-ran the nine-probe cases from the issue, each in an isolated
package (a type error aborts before MIR, so one E0007 can mask another
case):

Receiver Generic Type args canary 304898ab3 this branch
Repeat.new(7) yes inferred ICE E0007
ArrayIterator.new([1, 2]) yes inferred ICE E0007
ProbeGen2.new(1) (user-space) yes inferred ICE E0007
Repeat<int> { value: 7, count: 3 } yes explicit E0007 E0007
ProbeGen<int> { v: 1 } (user-space) yes explicit E0007 E0007
Range.new(0, 3) no — E0007 E0007
ProbeUser { v: 1 } (user-space) no — E0007 E0007

Before:

=> internal compiler error: MIR failed to resolve field access .zzz_probe_beta
   against class definition 'Repeat' (module_path: ["baml", "iter"]).
   This class should be in class_fields but isn't.

After:

probe.baml:2:5-2:45 error[E0007]: type `baml.iter.Repeat<int>` has no member `zzz_probe_beta`

The receiver is reported as Repeat<int> rather than Repeat<?T>, so the
span and the type in the message are both usable.

No regressions I could find on the branch: the BAML corpus is 3325 passed
/ 0 failed, and cargo test -p baml_tests --lib is 935 passed / 0 failed
/ 5 ignored. The four tests added here pass.

Note the branch is 64 commits behind canary, so I tested it as-is rather
than rebased.

Tested with AI assistance; I reviewed the results and re-ran the cases
before posting.

@sxlijin

sxlijin commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the underlying crash (#4506) was fixed on canary by #5038, which now reports E0155 for these cases. Not pursuing the E0007 refinement here.

@sxlijin sxlijin closed this Oct 22, 2026
@sxlijin
sxlijin deleted the sxlijin/gh-4506-inferred-generic-unknown-method-ice branch October 22, 2026 23:47

This branch was successfully deployed

1 active and 2 inactive (outdated) deployments
Preview – developer-docs — 6fa415fc Deployed Sep 17, 2026 by vercel[bot]
Preview – promptfiddle2 — 88a80007 Deployed Aug 19, 2026 by vercel[bot]
Preview – beps — 88a80007 Deployed Aug 19, 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.

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

2 participants