-
Notifications
You must be signed in to change notification settings - Fork 299
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
Bug fixes for array subtyping at returns / parameter passing #980
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44429bb
WIP
msridhar b150dd3
WIP
msridhar 51ee25f
one more test
msridhar d3b7d72
remove comment
msridhar 854b630
fix NullAway report
msridhar 22758c8
Merge branch 'master' into jspecify-array-returns-bug
msridhar dfa9945
Merge branch 'master' into jspecify-array-returns-bug
msridhar 4aa9da7
add comments for varargs test
msridhar 26b1eaf
couple more varargs tests
msridhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -278,6 +278,56 @@ public void arraysAndGenerics() { | |
.doTest(); | ||
} | ||
|
||
@Test | ||
public void genericArraysReturnedAndPassed() { | ||
makeHelper() | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import org.jspecify.annotations.Nullable;", | ||
"class Test {", | ||
" static class Foo<T> {}", | ||
" static class Bar<T> {", | ||
" Foo<T>[] getFoosPositive() {", | ||
" @Nullable Foo<T>[] result = new Foo[0];", | ||
" // BUG: Diagnostic contains: Cannot return expression of type @Nullable Foo<T>[] from method", | ||
" return result;", | ||
" }", | ||
" Foo<T>[] getFoosNegative() {", | ||
" Foo<T>[] result = new Foo[0];", | ||
" return result;", | ||
" }", | ||
" void takeFoos(Foo<T>[] foos) {}", | ||
" void callTakeFoosPositive(@Nullable Foo<T>[] p) {", | ||
" // BUG: Diagnostic contains: Cannot pass parameter of type @Nullable Foo<T>[]", | ||
" takeFoos(p);", | ||
" }", | ||
" void callTakeFoosNegative(Foo<T>[] p) {", | ||
" takeFoos(p);", | ||
" }", | ||
" void takeFoosVarargs(Foo<T>[]... foos) {}", | ||
" void callTakeFoosVarargsPositive(@Nullable Foo<T>[] p, Foo<T>[] p2) {", | ||
" // Under the hood, a @Nullable Foo<T>[][] is passed, which is not a subtype", | ||
" // of the formal parameter type Foo<T>[][]", | ||
" // BUG: Diagnostic contains: Cannot pass parameter of type @Nullable Foo<T>[]", | ||
" takeFoosVarargs(p);", | ||
" // BUG: Diagnostic contains: Cannot pass parameter of type @Nullable Foo<T>[]", | ||
" takeFoosVarargs(p2, p);", | ||
" }", | ||
" void callTakeFoosVarargsNegative(Foo<T>[] p) {", | ||
" takeFoosVarargs(p);", | ||
" }", | ||
" void takeNullableFoosVarargs(@Nullable Foo<T>[]... foos) {}", | ||
" void callTakeNullableFoosVarargsNegative(@Nullable Foo<T>[] p1, Foo<T>[] p2) {", | ||
" takeNullableFoosVarargs(p1);", | ||
" takeNullableFoosVarargs(p2);", | ||
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 about: 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 idea, added in 26b1eaf |
||
" takeNullableFoosVarargs(p1, p2);", | ||
" }", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void overridesReturnType() { | ||
makeHelper() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To be clear, the type of
foos
here ends up beingFoo<T>[][]
right? With a single element array passed in 311 that gets converted to the type@Nullable Foo<T>[][]
(meaning a two dimensional array of nullableFoo
s), correct?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.
Yes, that's right; added a comment in 4aa9da7. Note that we don't have support for multidim arrays yet in JSpecify mode, so we can't yet test passing in a
@Nullable Foo<T>[][]
array directly.