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

Eric Milles commented on GROOVY-10054:
--------------------------------------

[~chavan77]  I have been picking away at this problem over the years.  As you 
can see below, the 10054 and 10749 examples have their generics inferred for 
the direct assignment case.  This was a difficult step in itself.

The {{testTODO}} shows the next step where the assignment target's type 
arguments help to determine the untyped parameter's type.  This requires a more 
complete inference between source and target expressions.

If this next step could be solved, then I think it could be extended to the 
method call case.  Although, as discussed above there is an order of visitation 
to overcome for method calls.

 !screenshot-1.png!

Unfortunately, there isn't much more then social pressure brought to bear on 
this problem.

> STC: Cannot infer lambda parameter types for a stream collector
> ---------------------------------------------------------------
>
>                 Key: GROOVY-10054
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10054
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.0
>            Reporter: Lyuben Atanasov
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: screenshot-1.png
>
>
> 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();
>       }
>       <T extends Named> Map<String, List<T>> group(Set<T> 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.20.10#820010)

Reply via email to