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

Validate return types correctly. #4844

Merged
merged 3 commits into from Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion checker/tests/nullness/Issue1027.java
Expand Up @@ -19,7 +19,7 @@ class Repr<T> {
void bar(Function<T, String> p) {}
}

@SuppressWarnings("nullness")
@SuppressWarnings({"nullness", "keyfor"})
Repr<@KeyFor("this") String> foo() {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/nullness/java8inference/Issue1084.java
Expand Up @@ -7,7 +7,7 @@ class MyOpt<T extends Object> {
static <S> MyOpt<@NonNull S> empty() {
throw new RuntimeException();
}

// :: error: (type.argument)
static <S> MyOpt<S> of(S p) {
throw new RuntimeException();
}
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.IdentifierTree;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.ParameterizedTypeTree;
import com.sun.source.tree.Tree;
Expand Down Expand Up @@ -471,6 +472,14 @@ protected void visitTypeParameterBounds(
case TYPE_PARAMETER:
Copy link
Member

Choose a reason for hiding this comment

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

The Javadoc for the containing method twice says "type parameter tree" and once says "parameter type tree". Please make them consistent.

// Nothing to do.
break;
case METHOD:
// If a MethodTree is passed, it's just the return type that is validated.
// See BaseTypeVisitor#validateTypeOf.
MethodTree methodTree = (MethodTree) tree;
if (methodTree.getReturnType() instanceof ParameterizedTypeTree) {
typeargtree = (ParameterizedTypeTree) methodTree.getReturnType();
}
break;
default:
// The parameterized type is the result of some expression tree.
// No need to do anything further.
Expand Down