Fix false-negative when overriding method type-parameter bounds#7467
Fix false-negative when overriding method type-parameter bounds#7467Suvrat1629 wants to merge 4 commits intotypetools:masterfrom
Conversation
Signed-off-by: Suvrat1629 <suvrat1629@gmail.com>
Signed-off-by: Suvrat1629 <suvrat1629@gmail.com>
📝 WalkthroughWalkthroughThis 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)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 🧪 Unit Test Generation v2 is now available!We have significantly improved our unit test generation capabilities. To enable: Add this to your reviews:
finishing_touches:
unit_tests:
enabled: trueTry it out by using the 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. Comment |
There was a problem hiding this comment.
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.
Fixes #6864
BaseTypeVisitor.java: inserted a call tocheckTypeParameters()at the start ofOverrideChecker.checkOverride()and implementedprivate boolean checkTypeParameters()to compare corresponding method type variables using the existingtestTypevarContainment(...)helper and report failures viaFoundRequired.override.typeparaminmessages.propertiesto report incompatible method type-parameter bounds.