Skip to content

GROOVY-9848: Change map membership (in) from value-truthy to key-based#2642

Merged
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy9848
Jun 30, 2026
Merged

GROOVY-9848: Change map membership (in) from value-truthy to key-based#2642
paulk-asert merged 1 commit into
apache:masterfrom
paulk-asert:groovy9848

Conversation

@paulk-asert

@paulk-asert paulk-asert commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/!in through new runtime helpers (ScriptBytecodeAdapter.isIn/isNotIn) and update bytecode generation accordingly.
  • Guard DefaultGroovyMethods.isCase(Map, ...) with containsKey to prevent withDefault side effects in switch/grep.
  • Add/adjust regression tests covering map, string, withDefault, @CompileStatic, and @OperatorRename behavior.

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.

Comment thread src/main/java/groovy/transform/OperatorRename.java
@codecov-commenter

codecov-commenter commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.5438%. Comparing base (a7d75a5) to head (ea95f98).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 87.5000% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...us/groovy/classgen/asm/BinaryExpressionHelper.java 88.9368% <100.0000%> (+0.0319%) ⬆️
.../codehaus/groovy/runtime/DefaultGroovyMethods.java 74.9533% <100.0000%> (ø)
...ovy/transform/OperatorRenameASTTransformation.java 67.5676% <100.0000%> (+3.2111%) ⬆️
...roovy/transform/stc/StaticTypeCheckingVisitor.java 87.4584% <100.0000%> (+0.0161%) ⬆️
...codehaus/groovy/runtime/ScriptBytecodeAdapter.java 65.6542% <87.5000%> (+0.1780%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@paulk-asert paulk-asert changed the title GROOVY-9848: Allow membership operator to work on maps GROOVY-9848: Change map membership (in) from value-truthy to key-based Jun 29, 2026
@testlens-app

testlens-app Bot commented Jun 29, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: ea95f98
▶️ Tests: 102181 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

@paulk-asert paulk-asert merged commit aaa5126 into apache:master Jun 30, 2026
32 checks passed
@paulk-asert paulk-asert deleted the groovy9848 branch June 30, 2026 20:22
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.

4 participants