-
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
Treat Void return type as @Nullable Void when checking return statements #595
Conversation
@lazaroclapp should we open an issue with the reduced code example you found? |
@@ -728,6 +728,12 @@ private Description checkReturnExpression( | |||
// check for unboxing | |||
return returnType.isPrimitive() ? doUnboxingCheck(state, retExpr) : Description.NO_MATCH; | |||
} | |||
if (ASTHelpers.isSameType(returnType, Suppliers.JAVA_LANG_VOID_TYPE.get(state), state)) { |
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.
This is restoring precisely the behavior we had before #586; we only special-cased Void
for return types.
Pull Request Test Coverage Report for Build #844
💛 - Coveralls |
Might need some more careful rephrasing, but: #597 |
This is a follow up on #595. See that PR for some of the soundness caveats related to method overriding and the nullability of Void in our current implementation. This does, however, avoid some otherwise awkward suppressions, as shown in #608. There are two correct ways of hadling Void: a) Having it default to `@Nullable` as a type, which requires us adding a "default nullability" for some types/classes and explictly contradicts JSpecify (jspecify/jspecify#51) b) Supporting generics, and requiring explictly annotating `@Nullable Void`. This will probably also require third-party libraries which we consider annotated (such as CF), to adopt this convention. I believe (b) is the way forward long-term, which means that, for now, this hack might be the best we can do without generics support. Once NullAway supports generics, both this change and #595 should be reverted.
This is a follow up on #595. See that PR for some of the soundness caveats related to method overriding and the nullability of Void in our current implementation. This does, however, avoid some otherwise awkward suppressions, as shown in #608. There are two correct ways of hadling Void: a) Having it default to `@Nullable` as a type, which requires us adding a "default nullability" for some types/classes and explictly contradicts JSpecify (jspecify/jspecify#51) b) Supporting generics, and requiring explictly annotating `@Nullable Void`. This will probably also require third-party libraries which we consider annotated (such as CF), to adopt this convention. I believe (b) is the way forward long-term, which means that, for now, this hack might be the best we can do without generics support. Once NullAway supports generics, both this change and #595 should be reverted.
This is a follow up on #595. See that PR for some of the soundness caveats related to method overriding and the nullability of Void in our current implementation. This does, however, avoid some otherwise awkward suppressions, as shown in #608. There are two correct ways of handling Void: a) Having it default to `@Nullable` as a type, which requires us adding a "default nullability" for some types/classes and explicitly contradicts JSpecify (jspecify/jspecify#51) b) Supporting generics, and requiring explicitly annotating `@Nullable Void`. This will probably also require third-party libraries which we consider annotated (such as CF), to adopt this convention. I believe (b) is the way forward long-term, which means that, for now, this hack might be the best we can do without generics support. Once NullAway supports generics, both this change and #595 should be reverted.
This reverts the user-visible change from #586. We have found use cases involving generics and method overriding where requiring writing of
@Nullable Void
currently requires adding some ugly error suppressions. We need to think through those cases more carefully before requiring@Nullable
onVoid
.To be clear, this restored handling of
Void
is unsound. We treat aVoid
return type as@Nullable Void
when checkingreturn
statements (so they are allowed to returnnull
), but at call sites of methods with aVoid
return type, we assume the method will return a@NonNull
value. Also, if an overriding method has return typeVoid
, we treat it as@NonNull Void
, which leads to unsound checking of method subtyping.