docs: document the exhaustiveness vs. generics trade-off in match constructs#85
Conversation
|
Warning Review limit reached
More reviews will be available in 28 minutes and 37 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughREADME.md の ChangesREADME Type Safety ガイダンス更新
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Code Review
This pull request updates the README.md to clarify PHPStan's behavior regarding type narrowing and exhaustiveness checks, specifically comparing the use of instanceof in match (true) against the match() method and isOk()/isErr(). The reviewer suggested a minor phrasing improvement to use "preserves the type arguments" instead of "keeps T/E" for better terminology consistency with the rest of the text.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| plain `Ok`, so `unwrap()` becomes `mixed`), so use `instanceof` in a | ||
| `match (true)` purely for exhaustiveness. When you also need the values, prefer | ||
| the `match()` method — it is exhaustive by construction (both arms are required) | ||
| and keeps `T`/`E` — or narrow with `isOk()`/`isErr()`. (`isOk()`/`isErr()` arms |
There was a problem hiding this comment.
直前の文で loses the type arguments と表現されているため、こちらでも keeps T/E ではなく preserves the type arguments(または keeps the type arguments)と表現する方が、用語の一貫性と正確性の観点からより適切です。
| and keeps `T`/`E` — or narrow with `isOk()`/`isErr()`. (`isOk()`/`isErr()` arms | |
| and preserves the type arguments — or narrow with `isOk()`/`isErr()`. (`isOk()`/`isErr()` arms |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 40 40
===========================================
Files 2 2
Lines 80 80
===========================================
Hits 80 80
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Pull request overview
Updates the README’s “Type Safety” section to more precisely explain the PHPStan trade-off between (1) enforced exhaustiveness checking when using match (true) + instanceof, and (2) preserving generic type arguments when using match() or isOk()/isErr().
Changes:
- Rewrites the “Sealed interface” paragraph to clarify that enforced exhaustiveness and preserved generics are currently mutually exclusive in PHPStan 2.2.2.
- Documents that the
match()method preservesT/Eand requires both success/error handlers. - Adds context that
Resultis practically fixed toOk|Err, somatch()is total for real cases.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| `match (true)` purely for exhaustiveness. When you also need the values, the | ||
| `match()` method handles both cases and keeps `T`/`E` (it requires both an `ok` | ||
| and an `err` arm), or narrow with `isOk()`/`isErr()`. These two goals are a | ||
| trade-off in PHPStan 2.2.2: *enforced* exhaustiveness — where adding a new | ||
| `Result` variant would turn every unhandled site into an analysis error — comes | ||
| only from `instanceof` in a `match (true)`, which is exactly the form that drops | ||
| the type arguments. The `match()` method and `isOk()`/`isErr()` keep the generics | ||
| but are not checked against variant additions (`isOk()`/`isErr()` arms in a | ||
| `match (true)` also need a `default`). So per call site you currently pick one: | ||
| enforced exhaustiveness *or* preserved generics. (In practice `Result` is fixed | ||
| at `Ok|Err`, so the `match()` method covering both is total for all real cases.) |
概要
Type Safety セクションの Sealed interface の記述を、
match (true)における「厳密な網羅性チェック」と「ジェネリクス保持」のトレードオフを正確に説明する内容へ更新しました。背景(PHPStan 2.2.2 で実測)
3つ目の variant を sealed に追加して「未対応ハンドラが静的解析エラーになるか(=厳密な網羅性)」を検証した結果:
(variant 追加で自動エラー)
match (true)+instanceofOk→unwrap()がmixedisOk()/isErr()アームdefault必須で variant 追加を吸収)Ok<int>match()メソッドU|V厳密な(enforced)網羅性が得られるのは
match (true)+instanceofだけで、それは型引数を失うことが確定しました。match()メソッドは「現在の2アリティに対して total」ではあるものの、variant 追加に対する自動検出は行いません。変更内容
Resultは実際にはOk|Errの2値固定なので、match()メソッドが実用上は全ケースを賄える点も補足ドキュメントのみの変更です。