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

Paul King edited comment on GROOVY-8479 at 2/22/18 11:45 AM:
-------------------------------------------------------------

>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 define any parameter types and return type for 
{{plus}}.


was (Author: paulk):
>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)

Reply via email to