codeconsole opened a new pull request, #3250:
URL: https://github.com/apache/groovy/pull/3250
A method pointer assigned to or returned as a functional interface has its
return type checked since GROOVY-12623, against the common type of every
overload of the name. So an overloaded method that works on 6.0.0 no longer
compiles on master:
```groovy
@groovy.transform.CompileStatic
class C {
Function<Integer,Integer> f() { Math.&abs } // Possible
loss of precision from double to java.lang.Integer
BiFunction<Integer,Integer,Integer> g() { Math.&max } // same
}
```
An `Integer` argument selects `abs(int)` and `max(int,int)` at run time, so
`abs(double)` should not count.
The check now uses the methods that values of the functional interface's
parameter types can select: the best match for those types, and any method with
narrower parameter types, which a value of a subtype selects.
`ToIntFunction<Object> g = C.&f` with `int f(Object)` and `long f(Long)` is
still reported, as `f(Long)` may be called, and so is `ToIntFunction<Number> h
= Math.&abs`. All the candidates still count when the parameter types select
none of them, or when an instance method referenced through its class takes the
first parameter as its receiver. A method reference (`::`) is not affected.
#3134 (GROOVY-12607) includes this commit, as it depends on it.
## Tests
`MethodReferenceTest.testMethodPointerToOverloadsSelectedByParameterTypes`
fails without the change, on its assignments and return of `Math.&abs` and
`Math.&max`. It also runs them and covers the overloads that must still be
reported. `groovy.transform.stc.*` and `org.codehaus.groovy.classgen.asm.sc.*`
pass. The Checkstyle and CodeNarc gates pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]