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

John Wagenleitner commented on GROOVY-7905:
-------------------------------------------

I did a quick test compiling a class with 2.4.7 then running it with that 
version and the version of master with the fix and get a {{NoSuchMethodError}}

{code}
D:\Temp>java -cp .;d:\java\groovy-2.4.7\embeddable\groovy-all-2.4.7.jar foo.Bar
[7, null, null, 3]

D:\Temp>java -cp .;d:\Projects\groovy\target\libs\groovy-all-2.5.0-SNAPSHOT.jar 
foo.Bar
Exception in thread "main" java.lang.NoSuchMethodError: 
org.codehaus.groovy.runtime.DefaultGroovyMethods.withDefault(Ljava/util/List;Lgroovy/lang/Closure;)Ljava/util/List;
        at foo.Bar.socat(Bar.groovy:15)
        at foo.Bar.main(Bar.groovy:8)
{code}

{code:title=foo/Bar.groovy}
package foo

@groovy.transform.CompileStatic
class Bar {

        static void main(args) {
                Bar b = new Bar()
                List<Long> list = b.socat()
                list.add(7L)
                list.get(3)
                println list
        }

        List<Long> socat() {
                List<Long> list = [].withDefault{ Long.valueOf(it.toString()) }
                return list
        }

}
{code}

> ListWithDefault DGM methods aren't type inference friendly
> ----------------------------------------------------------
>
>                 Key: GROOVY-7905
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7905
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>
> For the following script:
> {code}
> @groovy.transform.CompileStatic
> def method() {
>     def list = [].withDefault{ it.longValue() }
>     list[0] = list[3]
>     assert list[0] == 3 && list[0].class == Long
> }
> method()
> {code}
> The list access call {{list[3]}} doesn't funnel through the 
> {{ListWithDefault.getAt(int)}} method but instead the {{DGM.getAt(List, 
> int)}} method since {{List}} is the inferred type. The {{withDefault}} 
> methods could instead return the more specific type and then the correct type 
> will be inferred and the expected behavior is observed.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to