Repository navigation
Fix inference bug with generic instance methods - #1654
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1654 +/- ##
============================================
+ Coverage 88.04% 88.06% +0.01%
- Complexity 3074 3076 +2
============================================
Files 105 105
Lines 10351 10354 +3
Branches 2095 2095
============================================
+ Hits 9114 9118 +4
+ Misses 582 581 -1
Partials 655 655 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
lazaroclapp
left a comment
There was a problem hiding this comment.
Don't understand the CI warnings on a random pre-existing comment, but modulo that, this LGTM!
Yeah, GitHub Actions is bringing in Javadoc warnings from the integration test jobs over to the code review tab now...should probably fix these warnings, but still. |
34ffd0a to
4da9aa3
Compare
4da9aa3 to
39d5b75
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java (1)
890-890: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winPreserve warning-enabled helpers for tests expecting inference failures.
These tests still contain
// BUG: Diagnostic contains: inference failure..., butmakeHelper()no longer enablesWarnOnGenericInferenceFailure;runInferenceForCall()suppresses that diagnostic otherwise.
nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java#L890-L890: use a warning-enabled helper forlocalsWithTypesFromDataflow.nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java#L935-L935: use it fornullableTypeVarToNonNullField.nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java#L1239-L1239: use it forselfContainedOptional.nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java#L1757-L1757: use it fornestedGenericMethodRepairPreservesTopLevelNullability.nullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java#L505-L505: use it forsuperWildcardToConcreteTypeVariable.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java` at line 890, Replace makeHelper() with the warning-enabled helper for the tests localsWithTypesFromDataflow, nullableTypeVarToNonNullField, selfContainedOptional, nestedGenericMethodRepairPreservesTopLevelNullability, and superWildcardToConcreteTypeVariable. Apply this in GenericMethodTests.java at lines 890-890, 935-935, 1239-1239, and 1757-1757, and WildcardTests.java at line 505-505, preserving the existing inference-failure diagnostics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java`:
- Line 890: Replace makeHelper() with the warning-enabled helper for the tests
localsWithTypesFromDataflow, nullableTypeVarToNonNullField,
selfContainedOptional, nestedGenericMethodRepairPreservesTopLevelNullability,
and superWildcardToConcreteTypeVariable. Apply this in GenericMethodTests.java
at lines 890-890, 935-935, 1239-1239, and 1757-1757, and WildcardTests.java at
line 505-505, preserving the existing inference-failure diagnostics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ae76f786-bb44-443d-bec0-83784f7a3b82
📒 Files selected for processing (3)
nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.javanullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.javanullaway/src/test/java/com/uber/nullaway/jspecify/WildcardTests.java
Since #1654, the executable type used for inference is the method's type as a member of its receiver, and computing it infers the receiver when the receiver is itself a generic call. inferCallType computed it twice for a call not yet inferred (constraints, then return type), and runInferenceForCall a third time for lambda argument types. Inference run from dataflow is never cached, so every generic call in a receiver chain doubled the work below it: checking a fluent chain such as `r.path(..).entity(..).isEqualTo(..)` repeated n times took O(4^n). Compute the executable type once and pass it to runInferenceForCall and generateConstraintsForCall. At 9 links, dataflow inference runs drop from 524,259 to 315; a 96-link chain now checks in under 1s. Adds GenericMethodTests.longChainOfGenericInstanceMethodCalls, which times out on master and passes in about 0.1s with the fix. No existing test's diagnostics change. I used Claude Code to bisect the regression to #1654, find the cause and write the fix and test. I have reviewed and understood all the changes. Assisted-by: Claude Code (claude-opus-5-5) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved generic method-call inference consistency, including for nested calls and chained method calls. * **Tests** * Added a regression test covering nullable-argument detection in a long chain of generic method calls. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Fix generic method inference to substitute type arguments from the invocation receiver before generating nullability constraints and reconstructing inferred types.
Previously, inference used the method’s declaration-site type. For a call such as a generic method returning
Von aBox<@Nullable Object>receiver, NullAway treated the return as the unconstrained type variableVinstead of@Nullable Object. The solver could consequently infer a non-null return and report a false-positive warning for a lambda returning that value.Implementation
Introduce a shared helper that:
Use this receiver-aware method type when:
getTreeType.This also removes duplicated receiver-substitution logic.
Tests
Added regression coverage for:
Stream.maplambda returned asList<?>, which should produce no warning;varinitialized from a generic instance method on an inferred nullable receiver, ensuring the nested nullable type argument is preserved.Summary by CodeRabbit
Summary
Bug Fixes
Tests