Skip to content

Type narrowing under early returns#3133

Merged
imalsogreg merged 2 commits intocanaryfrom
greg/narrowing-early-return
Feb 19, 2026
Merged

Type narrowing under early returns#3133
imalsogreg merged 2 commits intocanaryfrom
greg/narrowing-early-return

Conversation

@imalsogreg
Copy link
Contributor

@imalsogreg imalsogreg commented Feb 19, 2026

Summary by CodeRabbit

  • New Features

    • Improved type narrowing for conditions, early returns, null checks, instanceof/discriminant patterns, and truthiness; NOT now yields boolean
    • Field access now resolves across union members; combined types returned when applicable
    • Divergence detection for blocks/branches to better inform control-flow typing
  • Tests

    • Added comprehensive tests for early-return and condition-based narrowing
    • Updated test fixtures to remove expected diagnostic blocks and use no-diagnostics placeholders

@vercel
Copy link

vercel bot commented Feb 19, 2026

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

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Feb 19, 2026 7:55pm
promptfiddle Ready Ready Preview, Comment Feb 19, 2026 7:55pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

📝 Walkthrough
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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 summarizes the main change: implementing type narrowing behavior specifically in early-return control-flow patterns, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch greg/narrowing-early-return

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 and usage tips.

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Binary size checks passed

7 passed

Artifact Platform Gzip Baseline Delta Status
bridge_cffi Linux 4.0 MB 4.0 MB +61.0 KB (+1.5%) OK
bridge_cffi-stripped Linux 2.2 MB 2.1 MB +63.7 KB (+3.0%) OK
bridge_cffi macOS 3.3 MB 3.3 MB +45.6 KB (+1.4%) OK
bridge_cffi-stripped macOS 1.8 MB 1.7 MB +49.9 KB (+2.9%) OK
bridge_cffi Windows 3.3 MB 3.3 MB +50.8 KB (+1.6%) OK
bridge_cffi-stripped Windows 1.8 MB 1.8 MB +55.6 KB (+3.2%) OK
bridge_wasm WASM 1.3 MB 1.3 MB +38.9 KB (+3.0%) OK

Generated by cargo size-gate · workflow run

coderabbitai[bot]
coderabbitai bot previously requested changes Feb 19, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

coderabbitai[bot]
coderabbitai bot previously requested changes Feb 19, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines +502 to +508
// Case 3: if (cont) { <diverges> } else { ... }
// After the if, cond was false.
if let Some(else_br) = else_branch {
if definitely_diverges(*then_branch, body) && !definitely_diverges(*else_br, body) {
return extract_condition_narrowing(ctx, *condition, body, false);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Typo in comment: "cont" → "cond".

📝 Proposed fix
-    // Case 3: if (cont) { <diverges> } else { ... }
+    // Case 3: if (cond) { <diverges> } else { ... }

@imalsogreg imalsogreg enabled auto-merge February 19, 2026 19:45
@imalsogreg imalsogreg added this pull request to the merge queue Feb 19, 2026
Merged via the queue into canary with commit 8838648 Feb 19, 2026
42 of 43 checks passed
@imalsogreg imalsogreg deleted the greg/narrowing-early-return branch February 19, 2026 19:52
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