Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.7
-
None
Description
I have the following Groovy program
@groovy.transform.TypeChecked class Test { public static void main(String[] args) { println(foo(10)); } static Integer foo(Object x) { if (x instanceof Integer) { def bar = {x}; return bar(); } return 100; } }
Actual Behavior
The program does not compile, and I get the following error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: program.groovy: 10: [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.lang.Integer @ line 10, column 14. return bar(); ^1 error
Expected Behavior
Compile successfully.
In particular I would expect that the inferred type of the return type of closure is "Integer" and not "Object", as the closure is defined inside a block where the following condition holds.
x instanceof Integer