-
Notifications
You must be signed in to change notification settings - Fork 353
Run inference for generic method calls nested inside receivers #1571
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
c80f73e
b5a4ae2
eaeb5ba
416f7a4
d293b16
0e21eeb
4431838
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 |
|---|---|---|
|
|
@@ -1648,6 +1648,43 @@ String nonNullElse(@Nullable String nullableString, String defaultValue) { | |
| .doTest(); | ||
| } | ||
|
|
||
| @Test | ||
| public void nestedReceivers() { | ||
| makeHelperWithInferenceFailureWarning() | ||
| .addSourceLines( | ||
| "Test.java", | ||
| """ | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
| @NullMarked | ||
| class Test { | ||
| static class Foo<T extends @Nullable Object> { | ||
| static <U extends @Nullable Object> Foo<U> of(Foo<U> other) { | ||
| throw new RuntimeException(); | ||
| } | ||
| Foo<T> or(Foo<T> other) { return this; } | ||
| } | ||
| // infer Foo<@Nullable String> as the type of the Foo.of() call via | ||
| // its parameter, and use that type to determine the return type of | ||
| // the or() call is Foo<@Nullable String> | ||
| static Foo<@Nullable String> FOO = | ||
| Foo.of(new Foo<@Nullable String>()).or(new Foo<@Nullable String>()); | ||
|
|
||
| // like the case above, but more deeply nested | ||
| static Foo<@Nullable String> FOO2 = | ||
| Foo.of(new Foo<@Nullable String>()) | ||
| .or(new Foo<@Nullable String>()) | ||
| .or(new Foo<@Nullable String>()); | ||
|
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. A bit surprised we don't have an example here reporting an issue (e.g. where one of the
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. Good point, will add a true positive test |
||
|
|
||
| // a true positive case | ||
| // BUG: Diagnostic contains: incompatible types: Foo<@Nullable String> cannot be converted to Foo<String> | ||
| static Foo<String> WRONG = | ||
| Foo.of(new Foo<@Nullable String>()).or(new Foo<@Nullable String>()); | ||
| } | ||
| """) | ||
| .doTest(); | ||
| } | ||
|
|
||
| private CompilationTestHelper makeHelper() { | ||
| return makeTestHelperWithArgs( | ||
| JSpecifyJavacConfig.withJSpecifyModeArgs( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is nested call here just meaning a chained method call as the receiver? Or are there more complex cases? I know is in the test, but a brief example here would be great :)