You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2018/02/22 11:45:00 UTC

[jira] [Commented] (GROOVY-8479) sum from DefaultGroovyMethods does not have type information

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

Paul King commented on GROOVY-8479:
-----------------------------------

From memory it was related to us not requiring {{plus}} to be homogeneous and {{sum}} uses {{plus}} under the covers - apart from some special cases like the {{int[]}} overload where some efficiencies are assumed.

Consider:
{code}
def n1 = [1L, 2L, 3L]
def n2 = [1, 2, 3]
def n3 = ['a', 'b', 'c']

// types within collection determine result type
assert n1.sum(42) instanceof Long
assert n3.sum(42) instanceof String

// type of initial value determines result type
assert n2.sum(42L) instanceof Long
assert n2.sum(42) instanceof Integer
assert n2.sum('hi') instanceof String
{code}
But in general, anyone can defining any parameter types and return type for {{plus}}.

> sum from DefaultGroovyMethods does not have type information
> ------------------------------------------------------------
>
>                 Key: GROOVY-8479
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8479
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.4.13
>            Reporter: Michal Kordas
>            Priority: Major
>
> Overloads of {{org.codehaus.groovy.runtime.DefaultGroovyMethods#sum}} are missing type information. I don't see {{@ClosureParams}} or generics on any of them. 
> It should have been done in https://issues.apache.org/jira/browse/GROOVY-7283, but for some reason {{sum}} was not modified back then.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)