[ 
https://issues.apache.org/jira/browse/GROOVY-12837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18151882#comment-18151882
 ] 

ASF GitHub Bot commented on GROOVY-12837:
-----------------------------------------

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.




> STC: a value written to a raw or def map started from a map literal is 
> converted to the literal's inferred value type
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12837
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12837
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 7.0.0-alpha-1, 6.0.1
>            Reporter: Scott Murphy Heiberg
>            Priority: Blocker
>




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to