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 2023/04/30 14:19:00 UTC
[jira] [Commented] (GROOVY-11035) Inferred type is Object when having a complex inheritance chain of interfaces
[ https://issues.apache.org/jira/browse/GROOVY-11035?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17718058#comment-17718058 ]
Eric Milles commented on GROOVY-11035:
--------------------------------------
Like with Guava, this is a case of a bridge method that lacks generics information:
{code}
// Method descriptor #47 ()Ljava/lang/Object;
// Stack: 1, Locals: 1
public bridge synthetic java.lang.Object next();
0 aload_0 [this]
1 invokespecial org.apache.commons.collections4.iterators.AbstractEmptyIterator.next() : java.lang.Object [12]
4 areturn
Line numbers:
[pc: 0, line: 32]
Local variable table:
[pc: 0, pc: 5] local: this index: 0 type: org.apache.commons.collections4.iterators.EmptyListIterator
Local variable type table:
[pc: 0, pc: 5] local: this index: 0 type: org.apache.commons.collections4.iterators.EmptyListIterator<E>
{code}
We had to stick with the bridge/synthetic methods because the provide the necessary accessibility/visibility for Java 16+. I'm not sure what java compilers do in this circumstance, but the return type that is directly available is just Object.
https://github.com/apache/commons-collections/blob/master/src/main/java/org/apache/commons/collections4/iterators/EmptyListIterator.java
> Inferred type is Object when having a complex inheritance chain of interfaces
> -----------------------------------------------------------------------------
>
> Key: GROOVY-11035
> URL: https://issues.apache.org/jira/browse/GROOVY-11035
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Eric Milles
> Priority: Minor
>
> This seems related to GROOVY-11012.
> I have the following program
> {code}
> @Grab('org.apache.commons:commons-collections4:4.4')
> import org.apache.commons.collections4.iterators.*;
> class Main {
> @groovy.transform.TypeChecked test() {
> EmptyListIterator<Number> tmp = null
> Number x = tmp.next()
> }
> }
> {code}
> h3. Actual behavior
> {code}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> test.groovy: 6: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Number
> @ line 6, column 16.
> Number x = tmp.next();
> ^
> 1 error
> {code}
> h3. Expected behavior
> Compile successfully
> h3. Notes
> Tested against master (commit: ed4b33c8d5ac71ee4963d6bb391850593c59e5b1)
> https://commons.apache.org/proper/commons-collections/javadocs/api-4.4/org/apache/commons/collections4/iterators/EmptyListIterator.html
--
This message was sent by Atlassian Jira
(v8.20.10#820010)