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

JSpecify: fix crashes where declared parameter / return types were raw #989

Merged
merged 8 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ public static void checkTypeParameterNullnessForFunctionReturnType(
}

Type formalReturnType = methodSymbol.getReturnType();
if (formalReturnType.isRaw()) {
// bail out of any checking involving raw types for now
return;
}
Type returnExpressionType = getTreeType(retExpr, state);
if (formalReturnType != null && returnExpressionType != null) {
boolean isReturnTypeValid =
Expand Down Expand Up @@ -511,6 +515,10 @@ public static void compareGenericTypeParameterNullabilityForCall(
}
for (int i = 0; i < n; i++) {
Type formalParameter = formalParams.get(i).type;
if (formalParameter.isRaw()) {
// bail out of any checking involving raw types for now
return;
}
Type actualParameter = getTreeType(actualParams.get(i), state);
if (actualParameter != null) {
if (!subtypeParameterNullability(formalParameter, actualParameter, state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,36 @@ public void testRawTypeReceiverCast() {
.doTest();
}

@Test
public void pseudoAssignmentWithRawDeclaredTypes() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" static class A<T> {",
" void foo(T n) {}",
" }",
" static class B {",
" static void bar(A a) {}",
" static void m1(A<?> a) {",
" bar(a);",
" }",
" static A m2(A<?> a) {",
" return a;",
" }",
" @Nullable A<?> field;",
" void m3(A<?> a) {",
" field = a;",
" A local = a;",
" local = a;",
" }",
" }",
"}")
.doTest();
}

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