You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/06 21:29:00 UTC
[jira] [Commented] (GROOVY-10651) STC: closure parameter type inference for raw type that is iterable over type parameter
[ https://issues.apache.org/jira/browse/GROOVY-10651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17550666#comment-17550666 ]
Eric Milles commented on GROOVY-10651:
--------------------------------------
One part of this problem is that the generics for "Iterable<TN>" and "Iterator<TN>" are different for binary and source types. When ResolveVisitor processes the source, it sets the type "TreeNode<?>" as the redirect for the TN type (see [ResolveVisitor#resolveGenericsType|https://github.com/apache/groovy/blob/4fc7c5d290725b7120ee3466d81da2ce94e770d3/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java#L1493]). However, both the ASM and ClassLoader resolution (via ClassNodeResolver) leaves "TN -> Object" for the generics type.
Since the sample uses a raw type "void proc(TreeNode node)", there is no type argument for "TN" and so the ClassNode of the GenericsType is used instead. This is where "Cannot find matching method #proc(java.lang.Object)" comes from.
> STC: closure parameter type inference for raw type that is iterable over type parameter
> ---------------------------------------------------------------------------------------
>
> Key: GROOVY-10651
> URL: https://issues.apache.org/jira/browse/GROOVY-10651
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 2.5.17, 3.0.11, 4.0.3
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Major
>
> Consider the following:
> {code:java}
> abstract class TreeNode<TN extends TreeNode<?>> implements Iterable<TN> {
> @Override
> Iterator<TN> iterator() {
> }
> }
> {code}
> {code:groovy}
> void proc(TreeNode node) {
> node.eachWithIndex { child, index ->
> proc(child) // Cannot find matching method #proc(java.lang.Object)
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)