Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JSpecify subtyping checks for arrays#956

Merged
msridhar merged 28 commits intouber:masterfrom
msridhar:array-subtyping-jspecify
May 17, 2024
Merged

JSpecify subtyping checks for arrays#956
msridhar merged 28 commits intouber:masterfrom
msridhar:array-subtyping-jspecify

Conversation

@msridhar
Copy link
Collaborator

@msridhar msridhar commented May 16, 2024

Add checks for proper array subtyping (including nullability of array contents) at pseudo-assignments and for method overriding. We do not yet handle multi-dimensional arrays. Note that JSpecify allows for covariant array subtyping with respect to nullability (see jspecify/jspecify#65) which complicates the implementation a bit. Also some hacks are required since javac does not propagate the array contents nullability annotation into the types of the relevant trees in all cases.

@msridhar msridhar added the jspecify Related to support for jspecify standard (see jspecify.dev) label May 16, 2024
@codecov
Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 95.45455% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 86.12%. Comparing base (f4c4734) to head (075fa41).

Files Patch % Lines
...ava/com/uber/nullaway/generics/GenericsChecks.java 96.22% 0 Missing and 2 partials ⚠️
...away/src/main/java/com/uber/nullaway/NullAway.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #956      +/-   ##
============================================
+ Coverage     86.06%   86.12%   +0.06%     
- Complexity     2027     2040      +13     
============================================
  Files            81       81              
  Lines          6679     6708      +29     
  Branches       1287     1293       +6     
============================================
+ Hits           5748     5777      +29     
  Misses          518      518              
  Partials        413      413              

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

@msridhar msridhar changed the title [WIP] JSpecify subtyping checks for arrays JSpecify subtyping checks for arrays May 17, 2024
@msridhar msridhar marked this pull request as ready for review May 17, 2024 00:45
@msridhar msridhar requested review from lazaroclapp and yuxincs May 17, 2024 00:46
Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

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

LGTM!

" // legal (covariant array subtypes)",
" x2 = nonnullIntArr;",
" // BUG: Diagnostic contains: Cannot assign from type @Nullable Integer[] to type Integer[]",
" x1 = nullableIntArr;",
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be clear, we don't try to infer nullability annotations for elements of local variables of array type or nullability of generics for object types, right? Or is it just that once assigned a @NonNull Integer[] then x1 must be assume to be incompatible with @Nullable Integer[]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't do any inference for array contents nullability. So when we declare Integer[] x1 = ... that means we are declaring that the array element type of x1 is @NonNull.

Comment on lines +410 to +412
if (isRHSNullableAnnotated && !isLHSNullableAnnotated) {
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@msridhar msridhar enabled auto-merge (squash) May 17, 2024 18:22
@msridhar msridhar merged commit e26e194 into uber:master May 17, 2024
@msridhar msridhar deleted the array-subtyping-jspecify branch May 17, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jspecify Related to support for jspecify standard (see jspecify.dev)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments