Skip to content
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

Substitute type arguments when checking type parameter nullability at call site #1070

Merged
merged 12 commits into from
Nov 13, 2024

Conversation

haewiful
Copy link
Contributor

  • I have made NullAway to check generic type paramater's nullability using type arguments explicityly passed at the call site.
  • The relevant unit test is void genericMethodAndVoidType() in the jspecify/GenericMethodTests.java file.

Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.88%. Comparing base (162defe) to head (3c8455b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...ava/com/uber/nullaway/generics/GenericsChecks.java 96.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1070      +/-   ##
============================================
+ Coverage     87.87%   87.88%   +0.01%     
- Complexity     2210     2217       +7     
============================================
  Files            85       85              
  Lines          7190     7196       +6     
  Branches       1423     1427       +4     
============================================
+ Hits           6318     6324       +6     
  Misses          438      438              
  Partials        434      434              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 630 to 640
if (tree instanceof MethodInvocationTree && methodSymbol.type instanceof Type.ForAll) {
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;

List<? extends Tree> typeArgumentTrees = methodInvocationTree.getTypeArguments();
com.sun.tools.javac.util.List<Type> explicitTypeArgs = convertTreesToTypes(typeArgumentTrees);

Type.ForAll forAllType = (Type.ForAll) methodSymbol.type;
Type.MethodType underlyingMethodType = (Type.MethodType) forAllType.qtype;
invokedMethodType =
state.getTypes().subst(underlyingMethodType, forAllType.tvars, explicitTypeArgs);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact logic (or very similar) now appears in multiple places. Can we extract it into a method that returns a method type with the generic type arguments substituted in?

@msridhar msridhar marked this pull request as ready for review November 13, 2024 23:37
Copy link
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@msridhar msridhar changed the title Check explicit type arguments when comparing generic type parameters nullability at call Substitute type arguments when checking parameter or return type at call site Nov 13, 2024
@msridhar msridhar changed the title Substitute type arguments when checking parameter or return type at call site Substitute type arguments when checking type parameter nullability at call site Nov 13, 2024
@msridhar msridhar enabled auto-merge (squash) November 13, 2024 23:48
@msridhar msridhar merged commit 7a3d088 into uber:master Nov 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants