Repository navigation
JSpecify: Improve handling of method references - #1430
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1430 +/- ##
============================================
- Coverage 88.38% 88.37% -0.01%
- Complexity 2674 2680 +6
============================================
Files 97 97
Lines 8866 8878 +12
Branches 1773 1777 +4
============================================
+ Hits 7836 7846 +10
Misses 511 511
- Partials 519 521 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WalkthroughThis change generalizes generics inference for poly-expressions by replacing lambda-only inference with a unified approach for LambdaExpressionTree and MemberReferenceTree. GenericsChecks renames getInferredLambdaType(...) to getInferredPolyExpressionType(...) and replaces the inferredLambdaTypes map with inferredPolyExpressionTypes. Call sites in NullAway and CoreNullnessStoreInitializer now prefer GenericsChecks.getInferredPolyExpressionType(...) (with ASTHelpers.getType fallback) when resolving generic nullness for lambda and method-reference parameter and return checks. Tests were added/updated for method references and annotated lambdas. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (7)📓 Common learnings📚 Learning: 2025-08-28T04:54:20.953ZApplied to files:
📚 Learning: 2025-08-14T18:50:06.159ZApplied to files:
📚 Learning: 2025-08-29T18:41:43.584ZApplied to files:
📚 Learning: 2025-10-29T23:56:18.236ZApplied to files:
📚 Learning: 2025-11-25T22:43:06.446ZApplied to files:
📚 Learning: 2025-12-31T23:59:20.009ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🔇 Additional comments (3)
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 |
|
Main Branch: With This PR: |
…guments (uber#2046) Three behaviors fixed by earlier changes had no test, so a regression in any of them would pass the suite. - uber#444: a null check on a cast around `Map.get`, as in `(String) m.get("k") == null ? "" : (String) m.get("k")`, did not refine `m.get("k")`, and the result was reported as `@Nullable`. uber#1997 fixed it by stripping reference casts when it computes access paths, but its tests cast a local or a map key, not the `get` result. The new `AccessPathsTests` case fails on f7b81c4, the parent of uber#1997, with `returning @nullable expression from method with @nonnull return type`. - uber#1290, method reference: `invoke(Test::returnsNull)` for `<R> void invoke(Supplier<@nullable R>)` and a `static @nullable Object returnsNull()` was reported with `Failed to infer type argument nullability` and `referenced method returns @nullable, but functional interface method Test.Supplier.get() returns @NonNull`. uber#1430 fixed it; its test passes an unbound receiver reference to a `Function`. The new case beside `supplierLambdaInference` fails with both diagnostics on 0b4156b, the parent of uber#1430. - uber#1290, dereference: inside `invoke`, dereferencing `supplier.get()` for a `java.util.function.Supplier<@nullable R>` is reported only with the JSpecify JDK models (`JSpecifyJDKModels=true`, or `JSpecifyExperimental=true`). Without them `Supplier` is unmarked and `get()` is not treated as `@Nullable`. The new `JSpecifyJDKModelsTest` case fails when its helper leaves out the models flag. The lambda case of uber#1290, `invoke(() -> null)`, is already covered by `supplierLambdaInference` (uber#1337). Fixes uber#444 Fixes uber#1290 Assisted-by: Claude Code (claude-opus-5-5) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Expanded coverage for nullability analysis involving casted map lookups, including checks that distinguish between matching and different keys. * Added JSpecify coverage for nullable values returned from suppliers and for nullability inferred through method references. * Added checks for the expected diagnostics when nullable values are dereferenced, alongside cases where no diagnostic is expected. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
We now infer the type of a method reference passed to a generic method based on the results of our generic method inference, similar to lambda expressions, and use this inferred type in appropriate places. Rewrite some of the code that previously referenced lambdas to now more generically reference poly expressions instead.
This is not full support, as we don't use method reference expressions in the inference process yet; see #1431. But that will be handled in a follow up.
Fixes #1128
Fixes #1307
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.