[ https://issues.apache.org/jira/browse/GROOVY-8445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16324104#comment-16324104 ]
Daniel Sun commented on GROOVY-8445: ------------------------------------ I found the issue when I tried to implement the native lambda, which is based on static analysis to gain the type information. testBinaryOperator and testUnaryOperator are skiped due to the issue: https://github.com/apache/groovy/blob/native-lambda/src/test/groovy/transform/stc/LambdaTest.groovy > Static analysis does not work properly when coercing Closure to > FunctionInterface > --------------------------------------------------------------------------------- > > Key: GROOVY-8445 > URL: https://issues.apache.org/jira/browse/GROOVY-8445 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker > Affects Versions: 3.0.0-alpha-1, 2.5.0-beta-2, 2.4.13, 2.6.0-alpha-2 > Reporter: Daniel Sun > > The following code fails when executing in static compilation mode. > {code:java} > import groovy.transform.CompileStatic > import java.util.stream.Collectors > import java.util.stream.Stream > > @CompileStatic // if we comment this line, the code works in > dynamic mode. > public class Test1 { > public static void main(String[] args) { > p(); > } > > public static void p() { > assert 13 == Stream.of(1, 2, 3).reduce(7, {r, e -> r + e}); > } > } > {code} > Here is the error message: > {code} > [Static type checking] - Cannot find matching method > java.util.stream.Stream#reduce(int, groovy.lang.Closure). Please check if the > declared type is correct and if the method exists. > at line: 12, column: 30 > [Static type checking] - Cannot find matching method > java.lang.Object#plus(java.lang.Object). Please check if the declared type is > correct and if the method exists. > at line: 12, column: 68 > {code} > Similarly, the following code fails in static compilation mode too: > {code:java} > import groovy.transform.CompileStatic > import java.util.stream.Collectors > import java.util.stream.Stream > > @CompileStatic // if we comment this line, the code works in dynamic > mode. > public class Test1 { > public static void main(String[] args) { > p(); > } > > public static void p() { > def list = [1, 2, 3] > list.replaceAll { e -> e + 10 } > assert [11, 12, 13] == list > } > } > {code} > Here is the error message: > {code} > [Static type checking] - Cannot find matching method > java.util.List#replaceAll(groovy.lang.Closure). Please check if the declared > type is correct and if the method exists. > at line: 13, column: 17 > [Static type checking] - Cannot find matching method > java.lang.Object#plus(int). Please check if the declared type is correct and > if the method exists. > at line: 13, column: 40 > {code} -- This message was sent by Atlassian JIRA (v6.4.14#64029)