Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSpecify: Handle @Nullable elements for enhanced-for-loops on arrays #986

Merged
merged 2 commits into from
Jun 22, 2024

Conversation

armughan11
Copy link
Collaborator

Currently, enhanced-for-loops do not honor nullability annotations on arrays.

Current Behavior
Both these dereferences work fine.

static @Nullable String[] fizz = {"1"}
for (String s: fizz){
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

New Behavior
The first one throws an error, as expected.

static @Nullable String[] fizz = {"1"}
for (String s: fizz){
     // BUG: Diagnostic contains: dereferenced expression s is @Nullable
     s.toString();
     if (s!=null){
          s.toString();
     }  
}

Fixes #983

Copy link

codecov bot commented Jun 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.95%. Comparing base (cc3dee3) to head (da98d36).

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #986   +/-   ##
=========================================
  Coverage     85.94%   85.95%           
- Complexity     2069     2070    +1     
=========================================
  Files            83       83           
  Lines          6860     6863    +3     
  Branches       1318     1319    +1     
=========================================
+ Hits           5896     5899    +3     
  Misses          550      550           
  Partials        414      414           

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

Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! Just a couple of minor comments

@@ -507,7 +508,6 @@ public TransferResult<Nullness, NullnessStore> visitAssignment(
Node rhs = node.getExpression();
Nullness value = values(input).valueOfSubNode(rhs);
Node target = node.getTarget();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this whitespace change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@armughan11 armughan11 requested a review from msridhar June 22, 2024 16:01
Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@msridhar msridhar merged commit 3ae9b23 into uber:master Jun 22, 2024
11 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.

In JSpecify mode, reason about array contents nullability in for-each loop over array
2 participants