-
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 generics checks for conditional expressions (#739)
For a conditional expression _e_, the type parameter nullability annotations of the true-subpart and false-subpart should match the annotations required by _e_'s context. E.g., if _e_ is the right-hand side of an assignment, the annotations should match those for the type parameters for the assignment's left-hand side: ```java // this is fine A<@nullable String> t = condition? new A<@nullable String> : new A<@nullable String>(); // this is bad A<@nullable String> t2 = condition? new A<String> : new A<String>(); // this is also bad A<@nullable String> t1 = condition ? new A<String>(): new A<@nullable String>() ``` Other contexts include returns, parameter passing, and being nested inside another conditional expression. In our experience, it seems that `javac` captures the type parameter nullability required by _e_'s context in the type of _e_ itself. So, our handling of conditional expressions simply checks that the types of both the true and false sub-expressions of _e_ are assignable to (i.e., a subtype of) the type of _e_, using the same machinery for checking assignments from #715.
- Loading branch information
1 parent
f743be3
commit d83b7d0
Showing
3 changed files
with
170 additions
and
0 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