[jira] [Commented] (GROOVY-6668) Static compiler doesn't coerce GString for getAt() call

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jira] [Commented] (GROOVY-6668) Static compiler doesn't coerce GString for getAt() call

JIRA jira@apache.org

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

Jochen Theodorou commented on GROOVY-6668:

To add on the written before...  so while I disagree, that m["$k"] should fail,{code}m["$k"].toUpperCase(){code} fails because we call getAt(String) form Object here. The method is defined to return Object, thus no toUpperCase() is possible. Since this is a Map<String,String> and we have the DGM <K,V> V getAt(Map<K,V> self, K key), we have in theory a kind of getAt(String):String method available. So for me the real problem here are the damn generics and shadowing of DGM within DGM. If you would define a DGM <V> getAt(Map<String,V> self, String key), I would expect the toUpperCase() to work.

> 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