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

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

codeconsole commented on PR #3089:
URL: https://github.com/apache/groovy/pull/3089#issuecomment-7073373766

   @daniellansun Thanks. I merged current master into the branch in 7823f759d6 
rather than rebasing, so no force-push. That picks up the `Groovy12720.groovy` 
fix, and `lintGate` passes locally. The only conflict was in 
`StaticTypeCheckingVisitor`, where master's GROOVY-12753/12755 rewrite of 
return-type inference met this PR's `inferGenericsOfCall`. I kept master's 
resolution logic and apply it to parameter types too. The description now says 
that a lambda written as a branch of a conditional isn't covered. While 
checking the operand case I found that `list << String::trim` didn't compile 
(class generation looked for `trim(T)`). That is fixed in 41eb183b9e, which 
gives the operand the interface's parameter types as an argument gets them. 
#3090 is stacked on this branch, so it will get master and these commits merged 
in.
   
   @paulk-asert On your point 2 (gate changes callers can observe), 5d3c725a5d 
does both things you suggested, one for each half:
   - **Lambdas are behind an option.** Statically compiled code now compiles a 
lambda for the interface only with the incubating 
`-Dgroovy.target.lambda.typearg=true` 
(`CompilerConfiguration.LAMBDA_TYPE_ARGUMENT`, forwarded by 
`org.apache.groovy-tested.gradle`). Without it the lambda is a closure as on 
master, so dynamic `list[0]()` and `.call()` keep working.
   - **Method references are not gated.** On master they were a compile error 
unless the type parameter's bound is a functional interface, so resolving them 
changes nothing that compiled before.
   - **Docs:** the `core-semantics.adoc` section covers both, including what 
callers can tell apart under the option.
   - **Tests:** `FunctionalTypeArgumentTest` pins the default, and 
`@TypeChecked` stays unchanged with and without the option.
   
   The STC and SC packages pass with the option off and on (5,958 tests).




> 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
>            Priority: Minor
>
> 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