GROOVY-9848: Change map membership (in) from value-truthy to key-based#2642
GROOVY-9848: Change map membership (in) from value-truthy to key-based#2642paulk-asert wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Implements GROOVY-9848 by decoupling the in/!in membership operators from isCase, making map membership key-based and CharSequence membership substring-based, while preserving switch/case and grep value-based isCase semantics (including avoiding withDefault map auto-growth during classification).
Changes:
- Route
in/!inthrough new runtime helpers (ScriptBytecodeAdapter.isIn/isNotIn) and update bytecode generation accordingly. - Guard
DefaultGroovyMethods.isCase(Map, ...)withcontainsKeyto preventwithDefaultside effects inswitch/grep. - Add/adjust regression tests covering map, string,
withDefault,@CompileStatic, and@OperatorRenamebehavior.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java | Adds isIn/isNotIn helpers implementing new membership dispatch rules. |
| src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java | Updates bytecode generation to use isIn/isNotIn for in/!in. |
| src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | Prevents withDefault auto-grow during map isCase classification. |
| src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | Adjusts static type checking metadata behavior for membership dispatch. |
| src/main/java/org/codehaus/groovy/transform/OperatorRenameASTTransformation.java | Adds explicit rename handling for in/!in operators (operand-reversed dispatch). |
| src/main/java/groovy/transform/OperatorRename.java | Exposes isIn/isNotIn rename hooks in the annotation API docs. |
| src/test/groovy/groovy/GroovyMethodsTest.groovy | Updates expectations for map and string membership semantics. |
| src/test/groovy/org/codehaus/groovy/transform/OperatorRenameTransformTest.groovy | Adds coverage for membership operator renaming (incl. @CompileStatic). |
| src/test/groovy/bugs/Groovy9848.groovy | Adds focused regression tests for GROOVY-9848 behavior and non-mutation guarantees. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2642 +/- ##
==================================================
+ Coverage 68.5420% 68.5438% +0.0018%
- Complexity 33730 33752 +22
==================================================
Files 1523 1523
Lines 127923 127959 +36
Branches 23251 23261 +10
==================================================
+ Hits 87681 87708 +27
- Misses 32464 32465 +1
- Partials 7778 7786 +8
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: ea95f98 Learn more about TestLens at testlens.app. |
See https://issues.apache.org/jira/browse/GROOVY-9848