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

ASF GitHub Bot commented on GROOVY-10979:
-----------------------------------------

paulk-asert opened a new pull request, #3359:
URL: https://github.com/apache/groovy/pull/3359

   On 6.0.x, keep the part of the fix that only accepts code 6.0.0 rejected: a 
method reference passed under static compilation for a parameter declared with 
a type parameter, such as E of List.add(E), is compiled for the functional 
interface the call binds it to.
   
   Leave out what changes code that compiled in 6.0.0, so the design can be 
settled for Groovy 7:
   - the incubating groovy.target.lambda.typearg option and its 
CompilerConfiguration constant: a lambda for such a parameter is compiled as a 
closure, as in 6.0.0
   - the operator operand path: list << String::trim stores a closure, as in 
6.0.0, which also removes the compiler crash for list << (String s) -> s.trim() 
under the option
   
   We could potentially bring more of 10979 into 6 but we need to think through 
a little more and avoid some of the breakages and compiler crashes.




> Cannot provide method reference to a type parameter instantiated with a SAM 
> type
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-10979
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10979
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Daniel Sun
>            Priority: Minor
>             Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> I have the following program
> {code}
> import java.util.function.*;
> import java.util.stream.*;
> public class Test {
>     public static void test() {
>       Stream<Number> x = null;
>       BiFunction<Function<String, Integer>, Number, Function<String, 
> Integer>> y = null;
>       BinaryOperator<Function<String, Integer>> z = null;
>       x.<Function<String, Integer>>reduce(Test::m, y, z);  // fails
>       x.reduce(Test::m, y, z);   // fails
>       x.reduce((d) -> 1, y, z);   // works
>     }
>     public static Integer m(String x) { return 1; }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
> failed:
> test.groovy: 12: The argument is a method reference, but the parameter type 
> is not a functional interface
>  @ line 12, column 43.
>    ction<String, Integer>>reduce(Test::m, y
>                                  ^
> test.groovy: 13: The argument is a method reference, but the parameter type 
> is not a functional interface
>  @ line 13, column 16.
>          x.reduce(Test::m, y, z);   // fails
>                   ^
> 2 errors
> {code}
> h3. Expected behavior
> Compile successfully
> Tested against master (commit: 55c6edfd81a64ce759357a3976070c0811bff637)



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to