Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.10
-
None
Description
Consider this piece of code:
void f() { } @CompileStatic String test1() { Closure<String> x = { if (true) { "asd" } else { f() null } } x.call() } @CompileStatic String test2() { Closure<String> x = { // Cannot assign Closure<Object> to Closure<String> if (true) { "asd" } else { f() } } x.call() } @CompileStatic String test3() { if (true) { "asd" } else { f() } }
The code in test1 compiles correctly. The type of the closure in test2 is inferred as Closure<Object> and that results in a static type checking error. There is an inconsistency here - in test3 the type inference yields String.
Basically - null s are not considered when the type is inferred. Calls to void methods should not be either.