Skip to content

Commit cc54c7f

Browse files
committed
add comment and move test
1 parent ebb70f9 commit cc54c7f

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ public Type visitMethodType(Type.MethodType t, Type other) {
292292

293293
@Override
294294
public Type visitClassType(Type.ClassType t, Type other) {
295-
// Unwrap wildcard upper bounds
296295
if (other instanceof Type.WildcardType wt) {
297296
if (wt.isExtendsBound()) {
298-
return visit(t, wt.type);
297+
// As a temporary measure, we restore nullability annotations from the upper bound of the
298+
// wildcard.
299+
// TODO revisit this decision when we add fuller support for inference and wildcards.
300+
return visit(t, wt.getExtendsBound());
299301
}
300302
}
301303

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodLambdaOrMethodRefArgTests.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,28 @@ void test() {
413413
.doTest();
414414
}
415415

416+
@Test
417+
public void genericMethodLambdaArgWildCard() {
418+
makeHelperWithInferenceFailureWarning()
419+
.addSourceLines(
420+
"Test.java",
421+
"""
422+
import org.jspecify.annotations.*;
423+
import java.util.function.Function;
424+
@NullMarked
425+
class Test {
426+
static <T, R> R invokeWithReturn(Function <? super T, ? extends @Nullable R> mapper) {
427+
throw new RuntimeException();
428+
}
429+
static void test() {
430+
// legal, should infer R -> Object but then the type of the lambda as
431+
// Function<Object, @Nullable Object> via wildcard upper bound
432+
Object x = invokeWithReturn(t -> null);
433+
}
434+
}""")
435+
.doTest();
436+
}
437+
416438
private CompilationTestHelper makeHelperWithInferenceFailureWarning() {
417439
return makeTestHelperWithArgs(
418440
JSpecifyJavacConfig.withJSpecifyModeArgs(

nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,28 +1042,6 @@ static class Foo<T extends @Nullable Object> {}
10421042
.doTest();
10431043
}
10441044

1045-
@Test
1046-
public void genericMethodLambdaArgWildCard() {
1047-
makeHelperWithInferenceFailureWarning()
1048-
.addSourceLines(
1049-
"Test.java",
1050-
"""
1051-
import org.jspecify.annotations.*;
1052-
import java.util.function.Function;
1053-
@NullMarked
1054-
class Test {
1055-
static <T, R> R invokeWithReturn(Function <? super T, ? extends @Nullable R> mapper) {
1056-
throw new RuntimeException();
1057-
}
1058-
static void test() {
1059-
// legal, should infer R -> Object but then the type of the lambda as
1060-
// Function<Object, @Nullable Object> via wildcard upper bound
1061-
Object x = invokeWithReturn(t -> null);
1062-
}
1063-
}""")
1064-
.doTest();
1065-
}
1066-
10671045
@Test
10681046
public void inferenceWithFieldAssignment() {
10691047
makeHelper()

0 commit comments

Comments
 (0)