Svatopluk Dedic created GROOVY-10217:
----------------------------------------

             Summary: 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
            Reporter: Svatopluk Dedic


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.

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to