[ https://issues.apache.org/jira/browse/GROOVY-11683?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17959351#comment-17959351 ]
Eric Milles edited comment on GROOVY-11683 at 6/10/25 4:38 PM: --------------------------------------------------------------- For the case of "stream" specifically, there are a few options: * {{default Stream<E> stream()}} of {{Collection<E>}} * {{public static <T> Stream<T> stream(final Iterable<T> self)}} of {{StreamGroovyMethods}} * {{public static <T> Stream<T> stream(final T self)}} of {{StreamGroovyMethods}} ".flatMap(List<UserType>::stream)" does propagate to the Collection method. There is a bug in the static check that prevents it from filling in the Iterable method. The Object/T method is not a good match, but is not [filtered out|https://github.com/apache/groovy/blob/31ad6a762af79e58a2a44d26105825337799badd/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L2631] (in Groovy 4) due to not knowing the expected arguments. was (Author: emilles): For the case of "stream" specifically, there are a few options: * {{default Stream<E> stream()}} of {{Collection<E>}} * {{public static <T> Stream<T> stream(final Iterable<T> self)}} of {{StreamGroovyMethods}} * {{public static <T> Stream<T> stream(final T self)}} of {{StreamGroovyMethods}} ".flatMap(List<UserType>::stream)" does propagate to the Collection method. There is a bug in the static check that prevents it from filling in the Iterable method. The Object/T method is not a good match, but is not filtered out (in Groovy 4) due to not knowing the expected arguments. This is [StaticTypeCheckingVisitor#filterMethodCandidates|https://github.com/apache/groovy/blob/31ad6a762af79e58a2a44d26105825337799badd/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L2631]. > 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)