Skip to content

Commit

Permalink
Handling casting from a non-nullable wildcard capture to a type varia…
Browse files Browse the repository at this point in the history
…ble.
  • Loading branch information
cpovirk committed Jan 19, 2021
1 parent eeba329 commit 559ba69
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/google/jspecify/nullness/NullSpecVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ private void ensureNonNull(Tree tree, String messageKey) {
}
}

@Override
protected boolean isTypeCastSafe(AnnotatedTypeMirror castType, AnnotatedTypeMirror exprType) {
/*
* TODO(cpovirk): I probably need to completely revisit this method to understand what it does
* and what the Right Way is to reconcile it with our non-standard treatment of wildcards and
* type variables.
*
* For now, the supermethod reports errors for some problematic casts (like from Object to int)
* but also reports errors for some safe casts (like from ? to T when the wildcard's
* corresponding type parameter doesn't permit null values). As an expedient measure, we
* short-circuit the check in the second case.
*/
return atypeFactory.isNullExclusiveUnderEveryParameterization(exprType)
|| super.isTypeCastSafe(castType, exprType);
}

@Override
protected String extraArgForReturnTypeError(Tree tree) {
/*
Expand Down

0 comments on commit 559ba69

Please sign in to comment.