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

CompileStatic ignores missing return statement

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Information Provided
    • 2.4.15
    • None
    • Static compilation

    Description

      The following simplified example compiles and executes, foo() returning false and bar() returning null.

      @CompileStatic
      class Pojo {
      
          boolean foo() {
          }
          
          Object bar() {
          }
      }
      

       

      With @CompileStatic enabled I would've expected sensible feedback from the compiler, example:

      error: missing return statement

       

      This symptom was discovered in a much larger method, where one branch was missing a return statement.
      I'm suggesting adding some sensible feedback in this type of scenario, in-order to support developers relying on @CompileStatic for sanity checking. This would adhere to the principle of least astonishment, as locating this type of logical error can be time-consuming.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dleh Daniel Hammer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: