Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.7, 4.0.0-alpha-2
-
None
Description
I have the following Groovy program.
class A {} @groovy.transform.CompileStatic class Main { static A bar(Object x) { if (x instanceof A) { def y = x // Inferred Object and not A y } else { new A() } } }
Actual Behavior
The program does not compile, and I get the following error.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Main.groovy: 9: [Static type checking] - Cannot return value of type java.lang.Object on method returning type A @ line 9, column 7. y ^ 1 error
Expected Behavior
Compile successfully.
Affected Version
I have also tested it with the compiler from Master (commit: 444f6a5e7f10b75d43d94e7bb4fe771ae384c321).