You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Pascal Schumacher (JIRA)" <ji...@apache.org> on 2016/01/15 19:28:39 UTC
[jira] [Closed] (GROOVY-7729) DefaultGroovyMethods.sum(Iterable) is
not CompileStatic aware
[ https://issues.apache.org/jira/browse/GROOVY-7729?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Pascal Schumacher closed GROOVY-7729.
-------------------------------------
Resolution: Won't Fix
Hi Fabiano,
thanks for reporting. Sadly expressing the return type of sum() just using generics is not possible, see [http://www.groovy-lang.org/mailing-lists.html#nabble-td5722710|a5722724] for a discussion (especially Cédrics comment).
> DefaultGroovyMethods.sum(Iterable) is not CompileStatic aware
> -------------------------------------------------------------
>
> Key: GROOVY-7729
> URL: https://issues.apache.org/jira/browse/GROOVY-7729
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.4, 2.4.5
> Environment: JDK 1.8.0_51/win32
> Reporter: Fabiano Biagini
> Priority: Minor
>
> {noformat}
> @groovy.transform.CompileStatic
> void bug() {
> int a = [1,2,3].sum()
> }
> {noformat}
> The code above works correctly with CompileDynamic, but CompileStatic will produce the following error:
> {noformat}
> [Static type checking] - Cannot assign value of type java.lang.Object to variable of type int
> {noformat}
> Seems to be a problem of DefaultGroovyMethods.sum(Iterable).
> I think it just need to be changed from
> {noformat}
> public static Object sum(Iterable self)
> {noformat}
> to
> {noformat}
> public static <T> T sum(Iterable<T> self)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)