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 for crash with wildcard types #1020

Merged
merged 3 commits into from
Aug 18, 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 @@ -5,6 +5,7 @@
import com.sun.tools.javac.code.Types;
import java.util.List;
import javax.lang.model.type.NullType;
import javax.lang.model.type.TypeKind;

/**
* Visitor that checks for identical nullability annotations at all nesting levels within two types.
Expand All @@ -23,6 +24,10 @@ public Boolean visitClassType(Type.ClassType lhsType, Type rhsType) {
if (rhsType instanceof NullType || rhsType.isPrimitive()) {
return true;
}
if (rhsType.getKind().equals(TypeKind.WILDCARD)) {
// TODO Handle wildcard types
return true;
}
Types types = state.getTypes();
// The base type of rhsType may be a subtype of lhsType's base type. In such cases, we must
// compare lhsType against the supertype of rhsType with a matching base type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,28 @@ public void issue1008() {
.doTest();
}

@Test
public void issue1014() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"import java.util.function.Function;",
"class Test<R> {",
" public interface PropertyFunction<",
" T extends @Nullable Object, R extends @Nullable Object, E extends Exception>",
" extends Function<T, R> {",
" R _apply(T t) throws E;",
" }",
" @Nullable PropertyFunction<? super R, ? extends String, ? super Exception> stringFunc;",
" public void propertyString() {",
" var f = stringFunc;",
" }",
"}")
.doTest();
}

private CompilationTestHelper makeHelper() {
return makeTestHelperWithArgs(
Arrays.asList(
Expand Down