Stefanos Chaliasos created GROOVY-9953:
------------------------------------------

             Summary: Type from flow typing is not propagated in variable 
assignments
                 Key: GROOVY-9953
                 URL: https://issues.apache.org/jira/browse/GROOVY-9953
             Project: Groovy
          Issue Type: Bug
          Components: Static compilation, Static Type Checker
    Affects Versions: 4.0.0-alpha-2, 3.0.7
            Reporter: Stefanos Chaliasos


I have the following Groovy program.
{code:groovy}
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()
    }
  }
}

{code}
h2. Actual Behavior

The program does not compile, and I get the following error.
{code:java}
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

{code}
h2. Expected Behavior

Compile successfully.

h2. Affected Version
I have also tested it with the compiler from Master (commit: 
444f6a5e7f10b75d43d94e7bb4fe771ae384c321).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to