Repository navigation
Treat a parenthesized lambda or method reference like an unwrapped one in generics checks - #2012
Conversation
…e in generics checks In JSpecify mode, NullAway reported different warnings for a lambda or method reference wrapped in parentheses than for the same expression without them. This is a variation of uber#1993, which uber#1999 fixed for lambdas and method references passed to unmarked code. Assigning a parenthesized lambda to a field of a parameterized receiver reported a false `incompatible types` warning and missed the dereference inside the body: box.field = (t -> { t.length(); return ""; }); // Box<String>, field is @nullable Function<@nullable T, T> incompatible types: @nullable Function<String, String> cannot be converted to @nullable Function<@nullable T, T> The unparenthesized form reports only `dereferenced expression 't' is @Nullable`. A parenthesized method reference in the same position missed `parameter s of referenced method is @NonNull`. Passing a parenthesized lambda or method reference to a generic method reported a false positive where the unparenthesized form reported nothing, for example after a null-rejecting filter with the JSpecify JDK models turned off: xs.stream().filter(Objects::nonNull).map((x -> x.length())) dereferenced expression 'x' is @nullable xs.stream().filter(Objects::nonNull).map((Test::len)) parameter s of referenced method is @nonnull, but parameter in functional interface method java.util.function.Function.apply(@nullable String) is @nullable Both checks recorded the target-derived type of a poly expression only when the right-hand side or the argument was itself a lambda or method reference, while every reader of that type looks it up under the tree with parentheses stripped. Assignment checking and the storing of inferred argument types after generic method inference now strip parentheses before the check and store the type under the unwrapped tree. The remaining `LambdaExpressionTree` and `MemberReferenceTree` checks in `GenericsChecks` and `GenericsUtils` already receive a stripped tree or test the enclosing path rather than an argument. Assisted-by: Claude Code (claude-opus-5-5)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughAssignment checks and generic-call inference now strip surrounding parentheses before recognizing lambdas and method references. Tests cover parenthesized expressions assigned to generic fields and used in stream operations, including cases with and without null-rejecting filters. Suggested reviewers: Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2012 +/- ##
============================================
+ Coverage 88.78% 88.86% +0.08%
Complexity 38 38
============================================
Files 118 118
Lines 12543 12545 +2
Branches 2540 2541 +1
============================================
+ Hits 11136 11148 +12
+ Misses 641 630 -11
- Partials 766 767 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
In JSpecify mode, NullAway reported different warnings for a lambda or method reference wrapped in parentheses than for the same expression without them. This is a variation of #1993, which #1999 fixed for lambdas and method references passed to unmarked code.
Assigning a parenthesized lambda to a field of a parameterized receiver reported a false
incompatible typeswarning and missed the dereference inside the body:The unparenthesized form reports only
dereferenced expression 't' is @Nullable. A parenthesized method reference in the same position missedparameter s of referenced method is @NonNull.Passing a parenthesized lambda or method reference to a generic method reported a false positive where the unparenthesized form reported nothing, for example after a null-rejecting filter with the JSpecify JDK models turned off:
Both checks recorded the target-derived type of a poly expression only when the right-hand side or the argument was itself a lambda or method reference, while every reader of that type looks it up under the tree with parentheses stripped. Assignment checking and the storing of inferred argument types after generic method inference now strip parentheses before the check and store the type under the unwrapped tree. The remaining
LambdaExpressionTreeandMemberReferenceTreechecks inGenericsChecksandGenericsUtilsalready receive a stripped tree or test the enclosing path rather than an argument.Assisted-by: Claude Code (claude-opus-5-5)
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests