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

Static Type Checker: Cannot return null with type checking enabled

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Duplicate
    • 2.0-rc-2
    • 2.0-rc-3
    • None
    • None

    Description

      Example:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      File foo() {
        if(true) {
           return new File("blah")
        }
        return null
      }
      

      This results in

      [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.io.File -> java.io.File
       at line: 8, column: 10
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            graemerocher Graeme Rocher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: