diff --git a/checker/tests/nullness/Issue1027.java b/checker/tests/nullness/Issue1027.java index 48a445d93c2..89822314bc0 100644 --- a/checker/tests/nullness/Issue1027.java +++ b/checker/tests/nullness/Issue1027.java @@ -19,7 +19,7 @@ class Repr { void bar(Function p) {} } - @SuppressWarnings("nullness") + @SuppressWarnings({"nullness", "keyfor"}) Repr<@KeyFor("this") String> foo() { return null; } diff --git a/checker/tests/nullness/java8inference/Issue1084.java b/checker/tests/nullness/java8inference/Issue1084.java index b0fd270678d..89090458ae6 100644 --- a/checker/tests/nullness/java8inference/Issue1084.java +++ b/checker/tests/nullness/java8inference/Issue1084.java @@ -7,7 +7,7 @@ class MyOpt { static MyOpt<@NonNull S> empty() { throw new RuntimeException(); } - + // :: error: (type.argument) static MyOpt of(S p) { throw new RuntimeException(); } diff --git a/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeValidator.java b/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeValidator.java index 7cf3f0a8e86..234d4eacfbe 100644 --- a/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeValidator.java +++ b/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeValidator.java @@ -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; @@ -407,13 +408,13 @@ protected void visitTypeParameterBounds( } /** - * If {@code tree} has a type parameter tree, then the tree and its type is returned. Otherwise - * null and {@code type} are returned. + * If {@code tree} has a {@link ParameterizedTypeTree}, then the tree and its type is returned. + * Otherwise null and {@code type} are returned. * * @param tree tree to search - * @param type type to return if no parameter type tree is found - * @return if {@code tree} has a type parameter tree, then returns the tree and its type. - * Otherwise, returns null and {@code type}. + * @param type type to return if no {@code ParameterizedTypeTree} is found + * @return if {@code tree} has a {@code ParameterizedTypeTree}, then returns the tree and its + * type. Otherwise, returns null and {@code type}. */ private Pair<@Nullable ParameterizedTypeTree, AnnotatedDeclaredType> extractParameterizedTypeTree( Tree tree, AnnotatedDeclaredType type) { @@ -471,6 +472,14 @@ protected void visitTypeParameterBounds( case TYPE_PARAMETER: // 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.