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

Eric Milles commented on GROOVY-11683:
--------------------------------------

Do these intermediate types look correct?
{code:groovy}
def /*Stream<ListUsersResponse>*/ aaa = cognito.listUsersPaginator { 
it.userPoolId(cognitoUserPool) }.stream()
def /*Stream<List<UserType>>*/ bbb = aaa.map(ListUsersResponse::users)
def /*Stream<UserType>*/ ccc = bbb.flatMap(List::stream)
def /*Stream<String>*/ ddd = ccc.map(UserType::username)
def /*List<String>*/ eee = ddd.toList()
{code}

This (example) does work properly in Groovy 5:
{code:groovy}
class Scratch {
  @CompileStatic groovy11683(Scratch scratch) {
    def aaa = Stream.of(scratch)
    def bbb = aaa.map(Scratch::strings)
    def ccc = bbb.flatMap(List::stream)
    def ddd = ccc.map(Integer::valueOf)
  }
  List<String> strings() {
    [ 'a', 'b', 'c' ]
  }
}
{code}

I'm not sure about a Groovy 4 backport.  The order of visit for method args and 
method call is different for pointers/references.

> STC loses generic information on method reference
> -------------------------------------------------
>
>                 Key: GROOVY-11683
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11683
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 4.0.27
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Minor
>
> I am using a typical stream pipeline to get a list of pages of results and 
> flatMap them to the individual records:
> {code}
> // 
> software.amazon.awssdk.services.cognitoidentityprovider.CognitoIdentityProviderClient
>  cognito
> cognito.listUsersPaginator { it.userPoolId(cognitoUserPool) }
>   .stream()
>   .map(ListUsersResponse::users)
>   .flatMap(List::stream) // produces UserType
>   .map(UserType::username)
>   .toList()
> {code}
> Both groovyc and GRECLIPSE report the compile-time error
> {code}
> Failed to find class method 'username(java.lang.Object)' or instance method 
> 'username()' for the type: 
> software.amazon.awssdk.services.cognitoidentityprovider.model.UserType
> {code}
> The cause appears to be a failure to propagate the type information out of 
> the {{flatMap}} call: On hover, Eclipse correctly identifies the 
> {{List::stream}} as returning {{Stream<UserType>}}, but the {{flatMap}} is 
> reported as {{Stream<Object>}}. Inserting a type witness before the 
> {{flatMap}} call resolves the error. Both the loss of type information and 
> the incorrect error message appear to be bugs.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to