Groovy @CompileStatic coding error highlighting issues

Hi,

I'm experiencing some issues with error highlighting in Groovy code annotated with @CompileStatic. These issues are small, but consistent in many versions (14.1.x, 15 EAP releases so far).

There's some good code marked red, and there's some bad code not marked red.

class CompilationTest {

    @CompileStatic
    public
String[] badCodeGreen() {
        [ 'a string' ]
    }

    @CompileStatic
    public void
goodCodeRed() {
        List<String> l = ['a', 'b', 'c']
        l.eachWithIndex { String entry, int i ->
            // Do something
        
}
        l.eachWithIndex { String entry, Integer i ->
            // Do something
        
}
    }
}


The first method returns a list instead of an array, without casting - this gives a Groovy compilation error:

Error:(13, 9) Groovyc: [Static type checking] - Cannot return value of type java.util.List <java.lang.String> on method returning type java.lang.String[]

In the second method, IntelliJ will highlight the index parameter of the Closure red with the message 'Expected integer'. The compiler (and runtime) however have no problem with either form, so it's valid code.

Groovy version is currently 2.4.4 but I've seen the same with 2.4.3 and older versions of Groovy, I don't think the Groovy version is relevant.

Kind regards,

--Tim van der Leeuw

3 comments
Comment actions Permalink

Indeed somewhat related, especially the first one, but not quite the same.
Also not a case of good-code-marked-red.

--Tim

0

Please sign in to leave a comment.