[
https://issues.apache.org/jira/browse/GROOVY-11073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17727997#comment-17727997
]
Eric Milles commented on GROOVY-11073:
--------------------------------------
The overloads of greatest interest:
{code:java}
static <T> T max(T[] self)
static <T> T max(T[] self, Comparator<? super T> comparator)
static <T> T max(T[] self,
@ClosureParams(value=FromString.class,options={"T","T,T"}) Closure<?> closure)
{code}
STC selects "max(T[])" and I think the intent was "max(T[],Closure)". [~paulk]
has been experimenting with changing the closure variant to "maxBy". I tried
changing the closure in the call to accept 1 or 2 params and added type
arguments and was able to get STC to select the max-by variant. It is not easy
to specify which you mean, so maybe this variant should be renamed to maxBy for
Groovy 5+.
I will have a look at the param distance calculation, which should have a
high-value match for "(T[],Closure)".
> Cannot infer type of parameterized method when dealing with arrays
> ------------------------------------------------------------------
>
> Key: GROOVY-11073
> URL: https://issues.apache.org/jira/browse/GROOVY-11073
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Priority: Minor
>
> I have the following code
> {code}
> class Main {
> static final void test() {
> double[] x =
> Tuple.tuple(org.codehaus.groovy.runtime.ArrayGroovyMethods.max((double[][])
> null, { -> 1 })).getV1();
> }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> Main.groovy: 3: [Static type checking] - Cannot assign value of type
> (java.io.Serializable or java.lang.Cloneable) to variable of type double[]
> @ line 3, column 18.
> double[] x =
> Tuple.tuple(org.codehaus.groovy.runtime.ArrayGroovyMethods.max((double[][])
> null, { -> 1 })).getV1();
> ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successully
> Tested against master (commit: 73c0f12ab35427bc3e7fd76929b482df61e1b80d)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)