blackdrag commented on code in PR #3345:
URL: https://github.com/apache/groovy/pull/3345#discussion_r4663380271
##########
COMPATIBILITY.md:
##########
@@ -1674,6 +1674,43 @@ is still rejected.
`CompilerConfiguration.setClassTagPreemptionDisabled`) keeps the previous
behaviour.
+### Groovy 7 — a map literal stores a GString key as a String (GROOVY-3676)
+
+A map literal such as `["${key}": value]` used to store the key as a
+`GString`. A subscript renders a `GString` to a `String` before `Map.get`,
+and `String.equals` does not treat a `GString` as equal, so both
+`map["${key}"]` and `map[key]` returned null while iteration still showed
+the entry. The literal now stores the `String` from one `toString()` call,
+taken when the literal is evaluated. That is the same rendering a dynamic
+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.
Review 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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]