Hello guys,
I was working with Closures and testing the CompileStatic feature,
and I noticed a possible bug in the following code:
@groovy.transform.CompileStatic
class Foo{
def run(){
Closure a ={
int i ->
println "First closure "+ i
}
Closure b ={
String s ->
println "Second closure "+ s
}
a=b
a("Testing!")
}
}
Foo f = new Foo()
f.run()
With CS applied the code will fail to compile with the following
error:
[Static type checking] - Closure argument types: [int] do not match
with parameter types: [java.lang.String]
at line: 13, column: 11
The compiler is expecting an integer but since the variable 'a' is
re-assigned to a new piece of code that takes a String as a
parameter should this error be thrown?
But if I turn off the CS the code will work just fine. Is this
supposed to be like this?
Thanks,
Carlos