Skip to content

Assert the @Nullable type argument inferred for a var diamond local - #2041

Merged
msridhar merged 1 commit into
uber:masterfrom
vlsi:claude/issue-1633-retarget-todo
Oct 24, 2026
Merged

msridhar merged 1 commit into
uber:masterfrom
vlsi:claude/issue-1633-retarget-todo

Conversation

@vlsi

@vlsi vlsi commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

#1708 made var inferredFromInitializer = new Box<>(null); infer Box<@Nullable Object>, which fixed #1633. GenericDiamondTests.varLocalDoesNotProvideTargetTypeForDiamondInference only checked that the false passing @Nullable parameter warning on that line is gone, so it would also pass with a non-null type argument. It now dereferences inferredFromInitializer.get() and expects dereferenced expression 'inferredFromInitializer.get()' is @Nullable. As a control, a var initialized with new Box<>("x") is dereferenced with no diagnostic.

A var initialized with a conditional expression still gets no @Nullable type argument, with diamonds or with a generic method; #2038 tracks it. The TODO in ConditionalExprTests.varConditionalDoesNotProvideTargetTypeForGenericMethodInference linked #1633 for that case and now links #2038. varConditionalDoesNotProvideTargetTypeForDiamondInference lost its #1633 TODO in #1708 and asserted nothing about the inferred type; it now dereferences inferredFromInitializer.get() under the same TODO, so a fix for #2038 makes both tests fail at the dereference.

On a77c5fc^ (the commit before #1708), the strengthened diamond test fails with Did not see an error on line 19 matching dereferenced expression 'inferredFromInitializer.get()' is @Nullable.

Fixes #1633

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded coverage for nullness diagnostics involving generic type inference, diamond expressions, and conditional expressions, including checks for nullable and non-null values.

uber#1708 made `var inferredFromInitializer = new Box<>(null);` infer
`Box<@nullable Object>`, which fixed uber#1633.
`GenericDiamondTests.varLocalDoesNotProvideTargetTypeForDiamondInference`
only checked that the false `passing @nullable parameter` warning on that
line is gone, so it would also pass with a non-null type argument. It now
dereferences `inferredFromInitializer.get()` and expects `dereferenced
expression 'inferredFromInitializer.get()' is @Nullable`. As a control,
a `var` initialized with `new Box<>("x")` is dereferenced with no
diagnostic.

A `var` initialized with a conditional expression still gets no
`@Nullable` type argument, with diamonds or with a generic method; uber#2038
tracks it. The TODO in
`ConditionalExprTests.varConditionalDoesNotProvideTargetTypeForGenericMethodInference`
linked uber#1633 for that case and now links uber#2038.
`varConditionalDoesNotProvideTargetTypeForDiamondInference` lost its
uber#1633 TODO in uber#1708 and asserted nothing about the inferred type; it now
dereferences `inferredFromInitializer.get()` under the same TODO, so a fix
for uber#2038 makes both tests fail at the dereference.

Fixes uber#1633

Assisted-by: Claude Code (claude-opus-5-5)
@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 7f85800 and 2ce6a98.

📒 Files selected for processing: 2
  • nullaway/src/test/java/com/uber/nullaway/jspecify/ConditionalExprTests.java
  • nullaway/src/test/java/com/uber/nullaway/jspecify/GenericDiamondTests.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

Walkthrough

The tests update a TODO reference from issue 1633 to issue 2038. They also add conditional-expression and diamond-inference checks for dereferencing values inferred from nullable and non-null constructor arguments.

Possibly related issues

  • Issue 2038: The changes add tests for the conditional-expression inference behavior described by this issue.

Suggested reviewers: msridhar

Priority: ⬇️ Low

Change: Other

Merge Risk: ⚪ Minimal · up to 2ce6a

The test-only changes introduce no identified merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: strengthening assertions for the nullable type argument inferred for a var diamond local.
Description check Passed The description directly explains the strengthened tests, expected nullability diagnostics, control case, and updated conditional-expression TODO.
Linked Issues check Passed The only directly linked issue is #1633, and it is closed. Per the issue state, #1633 supplies historical context and does not impose active coding requirements. The reviewed tests document the behavi…
Out of Scope Changes check Passed The changes stay within the stated test scope. GenericDiamondTests adds nullable and non-null dereference assertions for diamond-inferred var locals. ConditionalExprTests updates the TODO reference to…
Full details: Linked Issues check

Explanation

The only directly linked issue is #1633, and it is closed. Per the issue state, #1633 supplies historical context and does not impose active coding requirements. The reviewed tests document the behavior that the PR reports as already implemented by #1708.

Full details: Out of Scope Changes check

Explanation

The changes stay within the stated test scope. GenericDiamondTests adds nullable and non-null dereference assertions for diamond-inferred var locals. ConditionalExprTests updates the TODO reference to #2038 and adds the corresponding deferred dereference assertion. These changes directly support the PR test objective.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.15%. Comparing base (7f85800) to head (2ce6a98).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2041   +/-   ##
=========================================
  Coverage     89.15%   89.15%           
  Complexity       38       38           
=========================================
  Files           119      119           
  Lines         12721    12721           
  Branches       2578     2578           
=========================================
  Hits          11341    11341           
  Misses          623      623           
  Partials        757      757           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@msridhar
msridhar added this pull request to the merge queue Oct 24, 2026
Merged via the queue into uber:master with commit 66e1b26 Oct 24, 2026
20 checks passed
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.

JSpecify: infer diamond type-argument nullability from constructor arguments without a target type

2 participants