From 7b6d087957033e9bbe1396667e6591da7f0d0714 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Wed, 13 Nov 2024 16:22:06 -0800 Subject: [PATCH] add test for issue 1035 --- .../nullaway/jspecify/GenericMethodTests.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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(