Skip to content

Honor overrides of getTypeDeclarationBounds in limitToBound and isValidUse - #8667

Open
mernst wants to merge 10 commits into
typetools:masterfrom
mernst:type-declaration-bounds-override
Open

mernst wants to merge 10 commits into
typetools:masterfrom
mernst:type-declaration-bounds-override

Conversation

@mernst

@mernst mernst commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Land after #8639.

AnnotatedTypeFactory.getTypeDeclarationBounds returns the qualifier upper bounds for a use of a type, and a checker can override it, as InterningAnnotatedTypeFactory does for enum types. Two places ignored such an override, because they called QualifierUpperBounds.getBoundQualifiers directly:

  • QualifierUpperBounds.limitToBound, which limits the qualifiers that PropagationTreeAnnotator gives to a cast or to the elements of an array initializer.
  • BaseTypeVisitor.isValidUse(AnnotatedDeclaredType, AnnotatedDeclaredType, Tree), which checks a use of a declared type. Its caller, BaseTypeValidator.visitDeclared, passes a declarationType whose primary qualifiers come from getTypeDeclarationBounds, and overrides such as GuiEffectVisitor.isValidUse and NTDVisitor.isValidUse read the bounds from declarationType. The default implementation now does too, instead of recomputing the bounds and ignoring declarationType's qualifiers.

Now limitToBound calls getTypeDeclarationBounds, and isValidUse uses the primary qualifiers of declarationType.

The test factory H1H2AnnotatedTypeFactory now overrides getTypeDeclarationBounds so that a class named H1S1Bounded has the bound @H1S1, though no annotation on the class says so. The new test framework/tests/h1h2checker/TypeDeclarationBoundsOverride.java checks a use, a cast, and an array initializer of H1S1Bounded. Without the fix, all 4 of its checks fail.

The Interning Checker's override is not observable through these paths, because InterningTypeAnnotator already adds @Interned to every enum type.

…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.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Qualifier checks now use the declared type’s primary annotations as upper bounds. Bound collection fills missing hierarchies with top qualifiers. New test checkers and fixtures cover complete and partial bounds across uses, casts, arrays, inheritance, and other declarations.

Change: Bug fix

Merge Risk: Minimal · up to fcc5e

The change makes qualifier checks on casts, array initializers and type uses honor checker overrides of declaration bounds, with new tests for complete and partial bounds. No merge-blocking risk was identified.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b2aa3ee and fcc5ef7.

Files selected for processing: 4

  • framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java
  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
  • framework/src/main/java/org/checkerframework/framework/type/QualifierUpperBounds.java
  • framework/src/test/java/org/checkerframework/framework/testchecker/h1h2checker/H1H2AnnotatedTypeFactory.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants