diff --git a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java index 2fbd4e68f0..7bbe2c4ddf 100644 --- a/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/jspecify/GenericMethodTests.java @@ -161,6 +161,35 @@ public void genericMethodAndVoidTypeWithInference() { .doTest(); } + @Test + public void issue1035() { + makeHelper() + .addSourceLines( + "Todo.java", + "import org.jspecify.annotations.*;", + "@NullMarked", + "public class Todo {", + " public static T foo(NullableSupplier code) {", + " return code.get();", + " }", + " public static void main(String[] args) {", + " // BUG: Diagnostic contains: returning @Nullable expression from method with @NonNull return type", + " Todo.foo(() -> null);", + " Todo.<@Nullable Object>foo(() -> null);", + " }", + " // this method should have no errors once we support inference for generic methods", + " public static void requiresInferenceSupport() {", + " // BUG: Diagnostic contains: returning @Nullable expression from method with @NonNull return type", + " Todo.foo(() -> null);", + " }", + " @FunctionalInterface", + " public interface NullableSupplier {", + " T get();", + " }", + "}") + .doTest(); + } + private CompilationTestHelper makeHelper() { return makeTestHelperWithArgs( Arrays.asList(