codeconsole opened a new pull request, #3340: URL: https://github.com/apache/groovy/pull/3340
[GROOVY-12561](https://issues.apache.org/jira/browse/GROOVY-12561), [GROOVY-12824](https://issues.apache.org/jira/browse/GROOVY-12824). Stacked on #3090 (GROOVY-12561) and #3338 (GROOVY-12824, itself on #3336); the commit of its own is the last one. #3090 makes a closure literal written for a slot declared with a type parameter implement the functional interface the call binds the type parameter to, and passed as an argument, or assigned to a subscript, property or named constructor argument, the closure gets the types of its parameters from the interface. #3338 gives a closure the interface's parameter types as an operator operand and as a branch of a conditional argument, for a parameter declared with the interface, and leaves a parameter declared with a type parameter to #3090. So on a `List<Function<String, String>>` these were still rejected with `Cannot find matching method java.lang.Object#toUpperCase()`: ```groovy list << { it.toUpperCase() } list.add(flag ? { it.toUpperCase() } : { it.trim() }) ``` The merge of #3338 makes a conditional argument of closures, which #3338 visits once the method is chosen, still implement the interface for a type parameter. The commit then gives such a closure the interface before it is visited, where its class implements the interface; a lambda branch gets it with `groovy.target.lambda.typearg`, where it is compiled for the interface. Type-checked code passes such a closure as before. The guide's sentence on parameter types now covers all these places. ## Tests `FunctionalTypeArgumentTest.testClosureLiteralGetsParameterTypesFromTheInterfaceAsAnOperandConditionalOrNamedArgument` fails without the commit for the operand, the conditional of closures and the conditional of lambdas, and checks that the stored values are closures implementing `Function`, and that `@TypeChecked` still rejects the operand. The full `:test` suite and the lint gate 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]
