-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSpecify: initial checks for generic type compatibility at assignments (
#715) This pull request adds the identical type parameter nullability checks for both sides of an assignment. for example `NullableTypeParam<@nullable String> nullableTypeParam = new NullableTypeParam<String>();` should generate an error as the type parameters of both sides of the assignment do not have the same Nullability annotations. This PR covers the following cases: - checks for the variable instantiation `A<String> a = new A<@nullable String>();` - checks for the assignments `A<@nullable String> t1 = new A<@nullable String>(); A<String> t2; t2 = t1;` - LHS and RHS with the exact same types `A<String> a = new A<@nullable String>();` - RHS being a subtype of LHS ```java class Test { class D<P extends @nullable Object> {} class B<P extends @nullable Object> extends D<P>{} void test1() { // BUG: Diagnostic contains: Cannot assign from type D<String> f = new B<@nullable String>(); } } ``` - nested generics `A<B<String>, String> a = new A<B<@nullable String>>();` The PR does not handle pseudo-assignments due to parameter passing / returns; that support will come in a follow-up PR. Also note that this PR only changes NullAway behavior when `JSpecifyMode` is enabled. Additionally, we don't currently have functioning support for checking compatibility of method references, lambdas, or inferred generic instantiations, but this PR includes tests to show that those cases do not produce false positive errors (just false negatives / missed detections).
- Loading branch information
1 parent
a2efa6e
commit 14d3693
Showing
4 changed files
with
577 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.