codeconsole opened a new pull request, #3366: URL: https://github.com/apache/groovy/pull/3366
https://issues.apache.org/jira/browse/GROOVY-12837 GROOVY-12535 converts a value written to a map by a property or subscript assignment to the map's value type, and COMPATIBILITY.md says a map whose value type is not known (`def`, raw or a wildcard) is written as before. That holds for `Map m = [:]`, but not when the variable starts from a literal with entries: the literal gives the variable the inferred type `LinkedHashMap<String,String>`, and the write is converted against it. ```groovy @CompileStatic def go(boolean ok) { Map hints = [threadTs: '1787.0001', username: 'Dana'] hints.settleReactionOk = ok hints.settleReactionOk // 6.0.0: false (Boolean). 6.0.1-SNAPSHOT and master: 'false' (String), which is truthy } ``` The same happens with `def` and `var`. Nothing is reported at compile time. **Change.** `mapValueTypeToConvertTo` now takes the map type of a local-variable receiver from the variable's declared type (`getOriginType()`) instead of its inferred type, for both the property and the subscript form. A variable declared `Map<String,String>` still converts, as GROOVY-12535 intends. A subscript write to a raw variable started from a literal (`m['b'] = ok`) is rejected as it is on 6.0.0, instead of being accepted and converted. **Tests.** Five added to `bugs/Groovy12535.groovy`: raw and `def` maps started from a literal keep the value, a raw variable reassigned to a typed map keeps the value, a declared `Map<String,String>` started from a literal still converts, and the subscript write to a raw map is rejected as before. Run locally: `bugs.Groovy12535` (34 pass), and before rebasing onto today's master, `groovy.transform.stc.*`, `org.codehaus.groovy.classgen.asm.sc.*` and `bugs.Groovy127*` (6,194 tests, 0 failures). GROOVY-12535 is also on GROOVY_6_0_X, so this would need a backport there before 6.0.1. -- 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]
