You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2022/02/03 22:33:01 UTC

[jira] [Closed] (GROOVY-10217) Type inference does not work with GDK class enhancements

     [ https://issues.apache.org/jira/browse/GROOVY-10217?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-10217.
------------------------------

> Type inference does not work with GDK class enhancements
> --------------------------------------------------------
>
>                 Key: GROOVY-10217
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10217
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.8
>            Reporter: Svatopluk Dedic
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> Consider the following code:
>  
> {code:java}
> @groovy.transform.TypeChecked
> public class T2 {
>     def m(Object v) {
>         if (v instanceof List) {
>             System.err.println v.get(1)
>             List x = (List)v;
>             System.err.println x[0]
>             //System.err.println v[0]           <--- Uncoment to get error
>         } else {
>             System.err.println "Not a list"
>         }
>     }
> }
> T2 t = new T2();
> t.m(Arrays.asList("a", "b"));
> {code}
> This code compiles. But when the marked line is uncommented, groovy produces an error:
> {quote}/tmp/g/ee/T.groovy: 9: [Static type checking] - Cannot find matching method java.lang.Object#getAt(int). Please check if the declared type is correct and if the method exists. 
>  @ line 9, column 32. 
>                System.err.println v[0]
> {quote}
> Basic inference works OK, as the *v.get(int)* call compiles, but seems the GDK enhancements (*List.getAt* which interfaces with the [] operator) are not considered.
> Tested on Groovy Version: 3.0.8 JVM: 11.0.5 Vendor: Oracle Corporation OS: Linux



--
This message was sent by Atlassian Jira
(v8.20.1#820001)