[
https://issues.apache.org/jira/browse/GROOVY-10756?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17606996#comment-17606996
]
J. Brébec edited comment on GROOVY-10756 at 9/20/22 8:45 AM:
-------------------------------------------------------------
With 3.13, the previous snippet works. However, this one doesn't :
{code}
@groovy.transform.CompileStatic
def cst2() {
def f = new Bridge().files[0]
f.name
}
{code}
The error is now:
{code}
Static type checking] - No such property: name for class: java.lang.Object
@ line 10, column 5.
f.name
^
1 error
{code}
I have updated the git repo.
was (Author: j3rem1e):
With 3.13, the previous snippet works. However, this one doesn't :
{code}
@groovy.transform.CompileStatic
def cst2() {
def f = new Bridge().files[0]
f.name
}
{code}
The error is now:
{code}
Static type checking] - No such property: name for class: java.lang.Object
@ line 10, column 5.
f.name
^
1 error
{code}
> STC: parameterized and bounded return value for java class property
> -------------------------------------------------------------------
>
> Key: GROOVY-10756
> URL: https://issues.apache.org/jira/browse/GROOVY-10756
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 3.0.11, 2.5.18, 4.0.4
> Reporter: J. Brébec
> Assignee: Eric Milles
> Priority: Major
> Fix For: 2.5.19, 3.0.13, 4.0.6
>
>
> Given:
> * A Java class having a method returning a generic Collection,
> * A groovy script compiled with "CompileStatic" and using the method of the
> JavaClass
> Then the type of the element of the collection is not correctly inferred.
> Example:
> {code}
> public class Bridge { // java
>
> public <T extends File> Collection<T> getFiles() {
> return null;
> }
> }
> {code}
> and the following script:
> {code}
> @groovy.transform.CompileStatic
> def cst() {
> new Bridge().files.collect { it.name }
> }
> {code}
> the compilation fails with the error:
> {code}
> [Static type checking] - No such property: name for class: java.lang.Object
> {code}
> Note:
> - It works in v3.0.10 but not in v3.0.11
> - It works if the class is defined in the groovy script
> - A repro is available here: https://github.com/j3rem1e/groovy-bug-generic
> ({{>mvn test}})
--
This message was sent by Atlassian Jira
(v8.20.10#820010)