Consider this:
package test70
import groovy.transform.CompileStatic
@CompileStatic
class Test70 {
void foo() {
Object v1 = 'a'
Object v2 = 'b'
[v1, v2].each {
v ->
if(v instanceof Map) {
v.entrySet().each { e ->
def s = e.value
if(s instanceof String)
e.value = s.toUpperCase()
}
}
}
}
}
An error is given on both occurrences of e.value, because e is evaluated as Object instead of Map.Entry.
This used to work until some version of the Greclipse plugin (now I'm on 4.3.0.v202107132103-e2009).
If I compile this with Gradle/Groovy, the JAR is built successfully.
If I remove @CompileStatic, I get underlining for v.entrySet() and again on both occurrences of e.value.
If I try to give e a type in the closure:
v.entrySet().each { Entry e ->
def s = e.value
if(s instanceof String)
e.value = s.toUpperCase()
}
I see this:
- with
@CompileStatic an additional error is given on Entry, saying it's expecting Object.
- without
@CompileStatic, instead, the underlining for e.value is fixed, so the situation improves.

Consider this:
An error is given on both occurrences of
e.value, becauseeis evaluated asObjectinstead ofMap.Entry.This used to work until some version of the Greclipse plugin (now I'm on 4.3.0.v202107132103-e2009).
If I compile this with Gradle/Groovy, the JAR is built successfully.
If I remove
@CompileStatic, I get underlining forv.entrySet()and again on both occurrences ofe.value.If I try to give
ea type in the closure:I see this:
@CompileStatican additional error is given onEntry, saying it's expectingObject.@CompileStatic, instead, the underlining fore.valueis fixed, so the situation improves.