You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "mgroovy (Jira)" <ji...@apache.org> on 2021/03/05 16:50:00 UTC
[jira] [Created] (GROOVY-9968) @TypeChecked Error: Members of
Iterable are Foo, not Object
mgroovy created GROOVY-9968:
-------------------------------
Summary: @TypeChecked Error: Members of Iterable<T extends Foo> are Foo, not Object
Key: GROOVY-9968
URL: https://issues.apache.org/jira/browse/GROOVY-9968
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 3.0.7
Environment: Windows 10
jdk-11.0.10.9-hotspot
IntelliJ 2020.3.2
Reporter: mgroovy
*Problem*
Trying to build the sample test code below fails with:
{code:java}
Groovyc: [Static type checking] - No such property: name for class: java.lang.Object
Groovyc: Expected parameter of type java.lang.Object but got simple.groovy.bugs.groovy3.gb_2021_03_05.iterable_t_extends.Foo
Groovyc: [Static type checking] - No such property: name for class: java.lang.Object
{code}
If we do not explicitly give the member type of the IterableTExtendsFoo iterable, Groovy assumes that the type is Object, even though it has been defined as being a subclass of Foo in the definition of IterableTExtendsFoo<T extends Foo>.
*Expected*
* Code should compile.
* If Groovy could not deduce that IterableTExtendsFoo has been initialized with a List<T extends Foo>, then it should reject the line where the IterableTExtendsFoo ctor is called.
*Sample Code*
{code:java}
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.junit.Ignore
import org.junit.Test
@TypeChecked
class Groovy3_Iterable_T_extends_Bug {
@Test
@Ignore
void 'Groovy 3-0-7 Members of Iterable T extends Foo are Foo'() {
// Compiler should reject the following line if the ctor arg would not of type List<T extends Foo>
final iterableTExtendsFoo = new IterableTExtendsFoo([new Foo('Sli'),new Foo('Msha'),new Foo('Dy'),])
//final iterableTExtendsFoo = new IterableTExtendsFoo<Foo>([new Foo('Sli'),new Foo('Msha'),new Foo('Dy'),]) // This works
println iterableTExtendsFoo.collect { "Hi, my name is: $it.name" }
println iterableTExtendsFoo.collect { Foo f -> "name=$f.name" }
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)