Repository navigation
GROOVY-3676: store a map literal's GString key as its String rendering - #3345
Open
daniellansun wants to merge 1 commit into
Open
daniellansun wants to merge 1 commit into
daniellansun wants to merge 1 commit into
Conversation
A subscript renders a GString to a String before Map.get, so a literal that kept the GString could not be read back with the same interpolation or with the equivalent String. The literal now stores that rendering. A spread still copies the keys the source map stored.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3345 +/- ##
==================================================
+ Coverage 74.9518% 74.9541% +0.0023%
- Complexity 48908 48941 +33
==================================================
Files 1768 1768
Lines 161213 161264 +51
Branches 31728 31744 +16
==================================================
+ Hits 120832 120874 +42
- Misses 28968 28974 +6
- Partials 11413 11416 +3
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: e492c1a Learn more about TestLens at testlens.app/docs. |
blackdrag
reviewed
Nov 23, 2026
| subscript assignment `map["${key}"] = value` already stored. A later change | ||
| to an interpolated value does not rename the entry. Two literal keys that | ||
| render the same text are one entry; the later value wins and the first | ||
| position is kept. |
Contributor
There was a problem hiding this comment.
This sounds wrong. In dynamic Groovy key=1; map = ["${key}": value]; map["${key}"] is still compiled the same. And actually your changed in DGM depends on that. You should try map."1" in dynamic Groovy for the GString case I mentioned. If I am right this will not find the entry, while m["1"] should. Where you did make a change is for static compilation though.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/GROOVY-3676
A map literal such as
["${key}": value]used to store the key as aGString. A subscript renders aGStringto aStringbeforeMap.get, andString.equalsdoes not treat aGStringas equal, so bothmap["${key}"]andmap[key]returned null while iteration still showed the entry.The literal now stores the
Stringfrom onetoString()call, taken when the literal is evaluated. That is the same rendering a dynamic subscript assignment already stored. A spread still copies the source map's keys unchanged, so aGStringpassed toMap.putstays distinct from the equivalentString.DefaultGroovyMethods.getAt(Map, Object)looks theGStringup as itself first and, only when that key is absent, as the renderedString. Static inference of such a literal key is nowString.This is a Groovy 7 behavior change, documented in
COMPATIBILITY.md. Do not sync toGROOVY_6_0_X. Coverage is inGroovy3676and the re-enabledRegressionTest.testGroovy3676.