-
Notifications
You must be signed in to change notification settings - Fork 291
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
Enforce correct type-use annotation locations for nested types #1045
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1045 +/- ##
============================================
+ Coverage 87.54% 87.56% +0.01%
- Complexity 2138 2155 +17
============================================
Files 83 83
Lines 7003 7030 +27
Branches 1367 1376 +9
============================================
+ Hits 6131 6156 +25
- Misses 451 452 +1
- Partials 421 422 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start! I think we are missing checking on various occurrences of annotated types, like method return types. We should be doing checking in all the places that this checker does it. Can we add that, and also tests?
if (hasNestedClass(state.getTypes(), symbol.type)) { | ||
errorMessage = | ||
new ErrorMessage( | ||
MessageTypes.NULLABLE_ON_WRONG_NESTED_CLASS_LEVEL, | ||
"Type-use nullability annotations should be applied on inner class"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't understand this check and why it occurs here? I think the check should occur independent of whether the initializer assignment is valid. If we need to possibly report multiple error messages from this method, we can use the state.reportMatch
API to report the errors and then just always return Description.NO_MATCH
.
if (types == null || type == null) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these null checks are necessary the parameters should be @Nullable
. But I don't think they are needed?
Enforce correct type-use annotation locations for nested types as per JSpecify norms. We enforce type-use annotations to be on the inner class and raise an error if they are not. For annotations that are both type use and declaration, we raise an error at an invalid location.
Current behavior
New behavior
For annotations which are both declaration and annotation and type-use, only
foo2
throws an error since the location isn't apt for either scenarios