Skip to content

Commit

Permalink
For type variables, read bounds from the corresponding type parameter.
Browse files Browse the repository at this point in the history
This doesn't matter with the current version of the checker, but it will
keep
[this test](https://github.com/jspecify/jspecify/blob/7b7ff42735cc7be39cc7c862121fb7b14853cfcf/samples/NullExclusiveAtomicReferenceNoArg.java#L92)
passing after we merge the upstream implementation of capture
conversion.
  • Loading branch information
cpovirk committed Mar 8, 2022
1 parent f23ec80 commit 824113a
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,27 @@ private boolean nullnessEstablishingPathExists(
}

private List<? extends AnnotatedTypeMirror> getUpperBounds(AnnotatedTypeMirror type) {
/*
* In the case of a type-variable usage, we ignore the bounds attached to it in favor of the
* bounds on the type-parameter declaration. This will become necessary (in certain cases) after
* we merge the upstream implementation of capture conversion.
*
* I won't claim to understand *why* it will be necessary. Maybe the bounds aren't getting
* copied from the declaration to the usage correctly. Or maybe they're getting copied but then
* CF is mutating/replacing them (since it seems to update *bounds* based on annotations on the
* *usage* in some cases -- though we've tried to short-circuit that).
*
* In any case, in our model for nullness checking, we always want to look at the original
* bounds. So whatever the reason we have different bounds here, we don't want them.
*
* My only worry is that I always worry about making calls to getAnnotatedType, as discussed in
* various comments in this file (e.g., in NullSpecTreeAnnotator.visitMethodInvocation).
*/
if (type instanceof AnnotatedTypeVariable && !isCaptured(type.getUnderlyingType())) {
AnnotatedTypeVariable variable = (AnnotatedTypeVariable) type;
type = getAnnotatedType(variable.getUnderlyingType().asElement());
}

switch (type.getKind()) {
case INTERSECTION:
return ((AnnotatedIntersectionType) type).getBounds();
Expand Down

0 comments on commit 824113a

Please sign in to comment.