[ https://issues.apache.org/jira/browse/GROOVY-8004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15802836#comment-15802836 ]
Shil Sinha commented on GROOVY-8004: ------------------------------------ Didn't have much time to look at this, but it appears to be a result of the distance calculation in StaticTypeCheckingSupport#chooseBestMethod(ClassNode, Collection<MethodNode>, ClassNode...) i.e. the extension methods distance is found to be less than the regular ones. > CompileStatic ImmutableList.size() calls DefaultGroovyMethods.size(Iterable) > ---------------------------------------------------------------------------- > > Key: GROOVY-8004 > URL: https://issues.apache.org/jira/browse/GROOVY-8004 > Project: Groovy > Issue Type: Bug > Components: Compiler > Affects Versions: 2.4.7 > Reporter: Jan Kanis > > Calling {{size()}} on a Guava ImmutableList (which implements {{List}}) under > {{@CompileStatic}} calls DefaultGroovyMethods.size(Iterable) instead > ImmutableList.size(). If the variable is of type {{List}} and the compiler > cannot deduce that it actually contains an {{ImmutableList}} the > {{List.size()}} method is called as expected. > The same bug exists for general Guava collections. > Obviously this is bad especially for large collections, where a {{size()}} > ends up taking linear time instead of constant time. > Example: > {code} > import com.google.common.collect.ImmutableList > import groovy.transform.CompileStatic > @CompileStatic > class TestClass { > public static void main(String[] args) { > ImmutableList<String> l = ImmutableList.copyOf(args) > List<String> ls = l as List > println(l.size()) // Calls DefaultGroovyMethods.size(Iterable) > println(ls.size()) // Calls List.size() > } > } > {code} > View the generated code with {{javap -p -c TestClass.class}} to see the calls > that were emitted. -- This message was sent by Atlassian JIRA (v6.3.4#6332)