Skip to content

Commit

Permalink
Add more bailouts for raw types (#1153)
Browse files Browse the repository at this point in the history
Fixes #1151 

The extra check in `CheckIdenticalNullabilityVisitor` is not needed to
fix this bug but seemed like a prudent addition.
  • Loading branch information
msridhar authored Mar 4, 2025
1 parent baf8f77 commit 635ecd2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
return true;
}
// bail out of checking raw types for now
if (rhsTypeAsSuper.isRaw()) {
if (rhsTypeAsSuper.isRaw() || lhsType.isRaw()) {
return true;
}
List<Type> lhsTypeArguments = lhsType.getTypeArguments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ private static boolean identicalTypeParameterNullability(
*/
private static boolean subtypeParameterNullability(
Type lhsType, Type rhsType, VisitorState state, Config config) {
if (lhsType.isRaw()) {
return true;
}
if (lhsType.getKind().equals(TypeKind.ARRAY) && rhsType.getKind().equals(TypeKind.ARRAY)) {
// for array types we must allow covariance, i.e., an array of @NonNull references is a
// subtype of an array of @Nullable references; see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,26 @@ public void rawTypes() {
.doTest();
}

@Test
public void rawVarargsParam() {
makeHelper()
.addSourceLines(
"Foo.java",
"import org.jspecify.annotations.NullMarked;",
"import org.jspecify.annotations.Nullable;",
"@NullMarked",
"public class Foo {",
" public interface Supplier<T extends @Nullable Object> extends java.util.function.Supplier<T> {",
" }",
" public static void waitForAll(Runnable callback, Supplier... suppliers) {",
" }",
" public static void test(Supplier<Object> sup2) {",
" waitForAll(() -> {}, sup2);",
" }",
"}")
.doTest();
}

@Test
public void nestedGenericTypeAssignment() {
makeHelper()
Expand Down

0 comments on commit 635ecd2

Please sign in to comment.