[ 
https://issues.apache.org/jira/browse/GROOVY-9617?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-9617:
--------------------------------
    Description: 
The subscript operator of Map transform {{GString}} keys to {{String}}. But 
{{put()}} does not. This is inconsistent.
 
{code:java}
class App {

    static void main(String[] args) {
        println("subscript works: "+subscriptWorks())
        println("put works: "+putWorks())
    }

    static def subscriptWorks() {
        def map = [:]
        def x = "toto"
        def key = "$x"

        map[key] = "value"

        return map.containsKey(key)
    }

    static def putWorks() {
        def map = [:]
        def x = "toto"
        def key = "$x"

        map.put(key,"value")

        return map.containsKey(key)
    }
}
{code}
Outputs this :
{code:java}
subscript works: false
subscript works: true
{code}
It would be better to either cast all key parameters of all methods from 
GString to String or none. The current behaviour is very confusing.

  was:
The subscript operator of Map transform {{GString}} keys to {{String. }}But 
{{put()}} does not. This is incoherent.

 
{code:java}
class App {

    static void main(String[] args) {
        println("subscript works: "+subscriptWorks())
        println("put works: "+putWorks())
    }

    static def subscriptWorks() {
        def map = [:]
        def x = "toto"
        def key = "$x"

        map[key] = "value"

        return map.containsKey(key)
    }

    static def putWorks() {
        def map = [:]
        def x = "toto"
        def key = "$x"

        map.put(key,"value")

        return map.containsKey(key)
    }
}
{code}
Outputs this :
{code:java}
subscript works: false
subscript works: true
{code}
It would be better to either cast all key parameters of all methods from 
GString to String or none. The current behaviour is very confusing.


> map.put(key,value) and map[key] = value differ is key is a GString
> ------------------------------------------------------------------
>
>                 Key: GROOVY-9617
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9617
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.10
>            Reporter: Laurent Martelli
>            Priority: Minor
>
> The subscript operator of Map transform {{GString}} keys to {{String}}. But 
> {{put()}} does not. This is inconsistent.
>  
> {code:java}
> class App {
>     static void main(String[] args) {
>         println("subscript works: "+subscriptWorks())
>         println("put works: "+putWorks())
>     }
>     static def subscriptWorks() {
>         def map = [:]
>         def x = "toto"
>         def key = "$x"
>         map[key] = "value"
>         return map.containsKey(key)
>     }
>     static def putWorks() {
>         def map = [:]
>         def x = "toto"
>         def key = "$x"
>         map.put(key,"value")
>         return map.containsKey(key)
>     }
> }
> {code}
> Outputs this :
> {code:java}
> subscript works: false
> subscript works: true
> {code}
> It would be better to either cast all key parameters of all methods from 
> GString to String or none. The current behaviour is very confusing.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to