[jira] [Commented] (GROOVY-10054) STC: Cannot infer lambda parameter types for a Stream Collector in a generic method

2021-04-26 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-10054:
--

The static type checker visits the non-closure method arguments before 
selecting the method, because it needs type information to choose the best fit. 
 So, to work around this, you can assign the collector to a local variable 
first, like this:
{code:groovy}
Map> group(Set set) {
Collector>> grouping =
Collectors.groupingBy(named -> named.getName())
set.stream().collect(grouping);
}
{code}

Not ideal, but should pass STC until this issue can be resolved.

> STC: Cannot infer lambda parameter types for a Stream Collector in a generic 
> method
> ---
>
> Key: GROOVY-10054
> URL: https://issues.apache.org/jira/browse/GROOVY-10054
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
> Environment: OpenJDK8
>Reporter: Lyuben Atanasov
>Assignee: Eric Milles
>Priority: Major
>
> This is a follow-up to GROOVY-10049. After the issue there had been fixed I 
> was able to progress further with a chain of Stream method calls. However, 
> the fix doesn't seem to cover the following case:
> {code}
> import java.util.stream.Collectors;
> class Test {
>   static interface Named {
>   String getName();
>   }
>Map> group(Set namedObjects) {
>   return namedObjects.stream()
>   .collect(Collectors.groupingBy(named -> 
> named.getName()));
>   }
>   
> }
> {code}
> With static type checking enabled, an error is produced:
> {noformat}
> Script_ce61a645759c941d687680111f9bedbd.groovy: 11: [Static type checking] - 
> Cannot find matching method java.lang.Object#getName(). Please check if the 
> declared type is correct and if the method exists.
>  @ line 11, column 44.
>ollectors.groupingBy(named -> named.getN
> {noformat}
> The difference between this issue and GROOVY-10049 is that the lambda passed 
> here is not directly assigned to a Stream method. Of course, the issue is 
> probably not limited to Collectors, but this is how I am able to reproduce it.
> I've tested this against 
> https://github.com/apache/groovy/commit/e07f0112c5eff8d9c6828bd0ddb69e4b7f7cc1d6



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (GROOVY-10054) STC: Cannot infer lambda parameter types for a Stream Collector in a generic method

2021-04-23 Thread Lyuben Atanasov (Jira)


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

Lyuben Atanasov commented on GROOVY-10054:
--

I have tried this without the method being generic as well. The following code 
still fails static type checking:
{code}
static interface Named {
String getName();
}

Map> group(Set namedObjects) {
return namedObjects.stream()
.collect(Collectors.groupingBy(named -> 
named.getName()));
}
}
{code}

> STC: Cannot infer lambda parameter types for a Stream Collector in a generic 
> method
> ---
>
> Key: GROOVY-10054
> URL: https://issues.apache.org/jira/browse/GROOVY-10054
> Project: Groovy
>  Issue Type: Bug
>  Components: Static Type Checker
> Environment: OpenJDK8
>Reporter: Lyuben Atanasov
>Priority: Major
>
> This is a follow-up to GROOVY-10049. After the issue there had been fixed I 
> was able to progress further with a chain of Stream method calls. However, 
> the fix doesn't seem to cover the following case:
> {code}
> import java.util.stream.Collectors;
> class Test {
>   static interface Named {
>   String getName();
>   }
>Map> group(Set namedObjects) {
>   return namedObjects.stream()
>   .collect(Collectors.groupingBy(named -> 
> named.getName()));
>   }
>   
> }
> {code}
> With static type checking enabled, an error is produced:
> {noformat}
> Script_ce61a645759c941d687680111f9bedbd.groovy: 11: [Static type checking] - 
> Cannot find matching method java.lang.Object#getName(). Please check if the 
> declared type is correct and if the method exists.
>  @ line 11, column 44.
>ollectors.groupingBy(named -> named.getN
> {noformat}
> The difference between this issue and GROOVY-10049 is that the lambda passed 
> here is not directly assigned to a Stream method. Of course, the issue is 
> probably not limited to Collectors, but this is how I am able to reproduce it.
> I've tested this against 
> https://github.com/apache/groovy/commit/e07f0112c5eff8d9c6828bd0ddb69e4b7f7cc1d6



--
This message was sent by Atlassian Jira
(v8.3.4#803005)