-
Notifications
You must be signed in to change notification settings - Fork 425
Fix issue #2358 Make Map.keySet() handle multiple argments to @KeyFor #7363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes modify KeyFor annotation handling in the Checker Framework's nullness checker. The main file is updated to merge KeyFor annotations from a Map's key type into the return type of keySet() invocations. A new method override handles type argument extraction and annotation merging through a private helper method. Additionally, new imports are introduced to support this logic. A test file is updated by removing a skip annotation and adding error diagnostic markers to specific test methods, enabling test execution with expected error annotations. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings📚 Learning: 2025-10-22T20:41:01.112ZApplied to files:
🧬 Code graph analysis (1)checker/src/main/java/org/checkerframework/checker/nullness/KeyForAnnotatedTypeFactory.java (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
🔇 Additional comments (2)
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 |
Summary
Enhance @KeyFor propagation for Map.keySet() by modifying addComputedTypeAnnotations in KeyForAnnotatedTypeFactory.
Problem
The element type of Set returned by Map.keySet() only carried @KeyFor for the current variable (e.g., "sharedCounts1") and did not inherit @KeyFor values from the Map’s key type argument (e.g., "sharedBooks").
Solution
Override addComputedTypeAnnotations in KeyForAnnotatedTypeFactory. When the tree is a Map.keySet() call, read @KeyFor values from the receiver Map’s key type argument and from the current Set element type, merge the names, and update the keySet() return type’s element with the combined @KeyFor.
Reference
#2358