Skip to content

Fix false-negative when overriding method type-parameter bounds#7467

Open
Suvrat1629 wants to merge 4 commits intotypetools:masterfrom
Suvrat1629:false-neg-6864
Open

Fix false-negative when overriding method type-parameter bounds#7467
Suvrat1629 wants to merge 4 commits intotypetools:masterfrom
Suvrat1629:false-neg-6864

Conversation

@Suvrat1629
Copy link

Fixes #6864

  • Added a method-level type-parameter bounds check in BaseTypeVisitor.java: inserted a call to checkTypeParameters() at the start of OverrideChecker.checkOverride() and implemented private boolean checkTypeParameters() to compare corresponding method type variables using the existing testTypevarContainment(...) helper and report failures via FoundRequired.
  • Introduced a new diagnostic message key override.typeparam in messages.properties to report incompatible method type-parameter bounds.

Suvrat1629 and others added 4 commits January 22, 2026 12:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

This pull request addresses a false negative in override checking by introducing type parameter bounds validation. A new test file demonstrates the issue where a subclass overrides a method and modifies type parameter bounds to allow nullable elements. The framework's BaseTypeVisitor is enhanced with a checkTypeParameters method that validates type parameter compatibility between overriding and overridden methods before other override validation checks. A corresponding error message key is added to report incompatible bounds violations. Together, these changes ensure that methods with modified type parameter constraints are flagged during compilation.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR successfully implements type-parameter bounds checking for method overrides [#6864], detecting incompatible type-parameter bounds and preventing false negatives.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the type-parameter bounds check for method overrides, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java`:
- Around line 4169-4199: The diagnostic currently passes a zero-based index
(Integer.toString(i)) to checker.reportError; change this to a human-friendly
type-parameter identifier by using the type parameter's name from the
AnnotatedTypeVariable (e.g., obtain the declared name from subVar — e.g.,
subVar's element/simpleName or a getter such as
getName()/getTypeParameterElement().getSimpleName().toString()) and pass that
instead; if the name cannot be retrieved reliably, fall back to a 1-based index
(Integer.toString(i + 1)). Ensure this change is applied where
checkTypeParameters calls checker.reportError for the override.typeparam
message.

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.

false negative when overriding method

1 participant