-
Notifications
You must be signed in to change notification settings - Fork 300
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
Treat Void formal arguments as @Nullable #613
Changes from all commits
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 |
---|---|---|
|
@@ -623,6 +623,36 @@ public void nullableOnJavaLangVoid() { | |
.doTest(); | ||
} | ||
|
||
@Test | ||
public void nullableOnJavaLangVoidWithCast() { | ||
defaultCompilationHelper | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import javax.annotation.Nullable;", | ||
"class Test {", | ||
" // Currently unhandled. In fact, it *should* produce an error. This entire test case", | ||
" // needs to be rethought once we properly support generics, such that it works on T v", | ||
" // when T == @Nullable Void, but not when T == Void. Without generics, though, this is the", | ||
" // best we can do.", | ||
" @SuppressWarnings(\"NullAway\")", | ||
" private Void v = (Void)null;", | ||
" Void foo1() {", | ||
" // temporarily, we treat a Void return type as if it was @Nullable Void", | ||
" return (Void)null;", | ||
" }", | ||
" // Temporarily, we treat any Void formal as if it were @Nullable Void", | ||
" void consumeVoid(Void v) {", | ||
" }", | ||
" @Nullable Void foo2() {", | ||
" consumeVoid(null); // See comment on consumeVoid for why this is allowed", | ||
" consumeVoid((Void)null);", | ||
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. From the test, it seems that this change makes us treat 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 this is meant to change is the interpretation of a It is not possible at this time to always annotate the formal as 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. Got it thanks! I was thinking about the actual rather than the formal 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. Just doing |
||
" return (Void)null;", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void staticCallZeroArgsNullCheck() { | ||
defaultCompilationHelper | ||
|
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.
Can we add a comment here indicating the formal is treated as if it were
@Nullable
? I think having the comment just at the call site confused me a bit