JSpecify subtyping checks for arrays#956
Conversation
Codecov ReportAttention: Patch coverage is
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. |
| " // legal (covariant array subtypes)", | ||
| " x2 = nonnullIntArr;", | ||
| " // BUG: Diagnostic contains: Cannot assign from type @Nullable Integer[] to type Integer[]", | ||
| " x1 = nullableIntArr;", |
There was a problem hiding this comment.
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[]?
There was a problem hiding this comment.
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.
| if (isRHSNullableAnnotated && !isLHSNullableAnnotated) { | ||
| return false; | ||
| } |
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.