Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10294

Variable's inferred type is upcasted to an Object

    XMLWordPrintableJSON

Details

    Description

      I am not sure if this is a bug or a feature (or a general limitation of flow typing employed by Groovy).

      I have the following program

      class A {
        A foo() {
          def x = new A()
          if (false) {
            x = null
          }
          x
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 7: [Static type checking] - Cannot return value of type java.lang.Object on method returning type A
       @ line 7, column 5.
             x
             ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Tested against master

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: