Repository navigation
Conversation
…at has no bound The new test still crashes, in BaseTypeVisitor.isValidUse.
Revert the limitToBound change; getBoundQualifiers now returns a bound in every hierarchy, so its callers, such as limitToBound and BaseTypeVisitor.isValidUse, need no special case.
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
…erriding method, and cache the test bounds
… bound in limitToBound
Land before #8667.
A checker can override
AnnotatedTypeFactory.getDefaultTypeDeclarationBounds()to return qualifiers in only some of its type hierarchies. ThenQualifierUpperBounds.getBoundQualifiers()returned no bound in the other hierarchies, and the Checker Framework crashed:QualifierUpperBounds.limitToBound(added in ExtractQualifierUpperBounds.limitToBoundfromPropagationTreeAnnotator.addAnnoOrBound#8592) throwsBugInCF("no bound for ...") for a cast or an array initializer. Before ExtractQualifierUpperBounds.limitToBoundfromPropagationTreeAnnotator.addAnnoOrBound#8592,PropagationTreeAnnotator.addAnnoOrBoundsilently skipped such a hierarchy.BaseTypeVisitor.isValidUsepasses the missing bound (null) toisSubtypeShallowEffective, which throws aNullPointerExceptionfor any use of a declared type.This pull request makes
getBoundQualifiersuse top as the bound in a hierarchy in which no bound is specified (by an annotation on the type's declaration, by@UpperBoundFor, or bygetDefaultTypeDeclarationBounds()). Top is also the bound that the default implementation ofgetDefaultTypeDeclarationBounds()returns, so a missing qualifier means "no restriction". Now every caller ofgetBoundQualifiersandgetTypeDeclarationBoundsgets exactly one bound in each hierarchy, and none of them needs a special case. The Javadoc ofgetDefaultTypeDeclarationBoundsandgetTypeDeclarationBoundsdocuments that.This pull request also changes which errors such a checker reports, not just whether it crashes.
BaseTypeVisitor.checkExtendsOrImplementsused to skip a hierarchy that had no bound. Now it compares top to the supertype's qualifier. As a result, a checker that overridesgetDefaultTypeDeclarationBounds()to return a partial set (and that did not crash, for example because it overridesisValidUse) can now reportdeclaration.inconsistent.with.extends.clauseordeclaration.inconsistent.with.implements.clausefor a class declaration such asclass Sub extends @H2S1 Super {}. The test classUsesWithoutBound.NoBoundSub2shows this.The new test checker
PartialBoundsH1H2Checkeris theH1H2CheckerwithgetDefaultTypeDeclarationBounds()returning only@H1S1, which is also its default qualifier in the H1 hierarchy. Because that bound is not top, the tests also check that the default bound is enforced in the H1 hierarchy. Its tests inframework/tests/h1h2checker-partial-bounds/exercise casts, array initializers, uses of types in fields, parameters, locals, arrays, primitives, and type arguments,new(including anonymous classes),getClass(), extends and implements clauses, enums, and declarations with explicit H1 or H2 bounds. Without the fix, both test files crash.