[ https://issues.apache.org/jira/browse/GROOVY-6668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16478299#comment-16478299 ]
Jochen Theodorou edited comment on GROOVY-6668 at 5/17/18 12:50 AM: -------------------------------------------------------------------- [~melix] to get this right... {code} def foo(String s){} def x = 1 foo("$x") {code} you want this code to fail because a String is not a GString? Additionally you want {code} def x = 1 String s = "$x" {code} to fail for the same reason? My point being m["$k"] is still of a different category than the two above, if we are talking here about getAt(Object). If there is getAt(String) we are talking about the first example I gave. And there is actually getAt(Object) for Map and getAt(String) for Object. This means both are available here. In dynamic Groovy it is therefore 100% legal and working to use a GString to find a String key in a map. What causes problems is using GString keys in the map literal and forcing the object variant like [("$k"):v], and then looking it up using just a String. But that is not what this issue is about. was (Author: blackdrag): [~melix] to get this right... {code} def foo(String s){} def x = 1 foo("$x") {code} you want this code to fail because a String is not a GString? > Static compiler doesn't coerce GString for getAt() call > ------------------------------------------------------- > > Key: GROOVY-6668 > URL: https://issues.apache.org/jira/browse/GROOVY-6668 > Project: Groovy > Issue Type: Bug > Components: Static compilation > Affects Versions: 2.3.0-beta-1, 2.4.0-rc-1 > Reporter: Luke Daley > Priority: Major > > This might not be a bug, but it's a behaviour change from 2.2. > {code} > @groovy.transform.CompileStatic > class OtherThing { > OtherThing() { > Map<String, String> m = [:] > def k = "foo" > m["$k"].toUpperCase() // fails, no method toUpperCase() on object > m[k].toUpperCase() // works > } > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)