-
Notifications
You must be signed in to change notification settings - Fork 293
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
Task2 #1053
base: master
Are you sure you want to change the base?
Task2 #1053
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1053 +/- ##
=========================================
Coverage 87.60% 87.60%
- Complexity 2203 2217 +14
=========================================
Files 85 85
Lines 7187 7271 +84
Branches 1415 1435 +20
=========================================
+ Hits 6296 6370 +74
- Misses 456 458 +2
- Partials 435 443 +8 ☔ 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 have a few comments. Also, can we add some tests for a method like this:
public static <T, U> void twoTypeVars(T first, U second) {
}
Maybe write some variants where only one of the type variables has a @Nullable
upper bound, and some calls where the wrong type argument is made @Nullable
. This is just to check that our indexing logic is matching type arguments to type variables correctly.
@@ -145,6 +148,73 @@ private static boolean[] getTypeParamsWithNullableUpperBound( | |||
return result; | |||
} | |||
|
|||
public static void checkInstantiationForGenericMethodCalls( |
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.
We should add Javadoc on this method
|
||
// base type that is being instantiated | ||
Type baseType = methodSymbol.asType(); | ||
List<Type> baseTypeArgs = baseType.getTypeArguments(); |
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.
Let's rename:
List<Type> baseTypeArgs = baseType.getTypeArguments(); | |
List<Type> baseTypeVariables = baseType.getTypeArguments(); |
@@ -715,6 +785,40 @@ public static Nullness getGenericReturnNullnessAtInvocation( | |||
MethodInvocationTree tree, | |||
VisitorState state, | |||
Config config) { | |||
|
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.
We need to update the Javadoc of getGenericReturnNullnessAtInvocation
to indicate it also handles generic methods, in addition to instance methods of generic classes (what it handled before)
@@ -715,6 +785,40 @@ public static Nullness getGenericReturnNullnessAtInvocation( | |||
MethodInvocationTree tree, | |||
VisitorState state, | |||
Config config) { | |||
|
|||
List<? extends Tree> typeArgumentTrees = tree.getTypeArguments(); |
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.
Does this new logic only apply to generic methods? If so, can we only run it for that case, by checking if the invoked method has any type variables, !invokedMethodSymbol.getTypeParameters().isEmpty()
?
// If it's not a ForAll type, handle it as a normal MethodType | ||
Type.MethodType methodTypeElse = (Type.MethodType) invokedMethodSymbol.type; | ||
substitutedReturnType = | ||
state | ||
.getTypes() | ||
.subst( | ||
methodTypeElse.restype, | ||
invokedMethodSymbol.type.getTypeArguments(), | ||
explicitTypeArgs); |
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 feel like if we only apply the new logic to generic methods, we will always get a ForAll
type and won't need this else
case
@@ -768,6 +884,51 @@ public static Nullness getGenericParameterNullnessAtInvocation( | |||
MethodInvocationTree tree, | |||
VisitorState state, | |||
Config config) { | |||
List<? extends Tree> typeArgumentTrees = tree.getTypeArguments(); |
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.
Same comment as above regarding only running the new logic when a generic method is being invoked
Thank you for contributing to NullAway!
Please note that once you click "Create Pull Request" you will be asked to sign our Uber Contributor License Agreement via CLA assistant.
Before pressing the "Create Pull Request" button, please provide the following:
Added support for generic identity functions with explicitly-typed nullness.
Related to the issue JSpecify: support generic methods #1035.
void genericNonNullIdentityFunction() and void genericNullAllowingIdentityFunction() unit tests are added to GenericMethodTests.java file.