-
Notifications
You must be signed in to change notification settings - Fork 351
Fix subtype checking for nested captured types #1663
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
Changes from all commits
4a94a89
3838064
0e13d56
7b3de10
9669ea8
ec8cb15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import com.uber.nullaway.NullAwayTestsBase; | ||
| import com.uber.nullaway.generics.JSpecifyJavacConfig; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import org.junit.Test; | ||
|
|
||
| public class WildcardTests extends NullAwayTestsBase { | ||
|
|
@@ -406,6 +407,31 @@ static void testNonNullSuperBound(Foo<? super String> f) { | |
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wildcardCaptureReturnPreservesNestedNullability() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| class Test { | ||
| static class Box<T extends @Nullable Object> {} | ||
| static class Holder<T extends @Nullable Object> { | ||
| T get() { | ||
| throw new RuntimeException(); | ||
| } | ||
| } | ||
| static void test(Holder<? extends Box<@Nullable String>> holder) { | ||
| // BUG: Diagnostic contains: incompatible types | ||
| Box<String> box = holder.get(); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void wildcardCaptureReturnWithTypeVariableUpperBound() { | ||
| makeHelper() | ||
|
|
@@ -979,6 +1005,57 @@ static class Analysis< | |
| .doTest(); | ||
| } | ||
|
|
||
| /** ensures we avoid a crash related to wildcards when wildcard handling is disabled */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the behavior when we do have wildcard handling enabled? Is that handled on a separate PR on the chain?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wildcard handling is enabled by default for our regression tests now. It's included as part of the JSpecify experimental flag that we include for any JSpecify test, which also includes the JSpecify JDK library models |
||
| @Test | ||
| public void methodRefParameterSuperWildcardWithHandlingDisabled() { | ||
| makeTestHelperWithArgs( | ||
| List.of( | ||
| "-XepOpt:NullAway:OnlyNullMarked=true", | ||
| JSpecifyJavacConfig.JSPECIFY_MODE_FLAG, | ||
| JSpecifyJavacConfig.ADD_TYPE_ANNOTATIONS_FLAG)) | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import java.util.function.Function; | ||
| import org.jspecify.annotations.NullMarked; | ||
| @NullMarked | ||
| final class Test { | ||
| static void reproduce() { | ||
| getOrThrow(Test::throwAsUncheckedException); | ||
| } | ||
| private static void getOrThrow(Function<? super Exception, RuntimeException> exceptionTransformer) { | ||
| } | ||
| private static RuntimeException throwAsUncheckedException(Throwable throwable) { | ||
| return new RuntimeException(throwable); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| /** reduced from a crasher found when checking junit */ | ||
| @Test | ||
| public void methodRefReturnUnboundedWildcard() { | ||
| makeHelper() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| package repro; | ||
| import java.util.concurrent.FutureTask; | ||
| import java.util.function.Supplier; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| final class Test { | ||
| private final FutureTask<@Nullable Object> task; | ||
| Test(Supplier<?> delegate) { | ||
| this.task = new FutureTask<>(delegate::get); | ||
| } | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullableOnWildcard() { | ||
| makeHelper() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.