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

Assignments in if/else/for/while/ternary are not type checked properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-beta-1
    • 2.0-beta-2
    • Static Type Checker
    • None

    Description

      The following code will pass, though the return type of x after the if/else statement may differ:

      def x
      if (cond) {
        x = new Date()
      } else {
        x = 123
      }
      x.toInteger()
      

      In a similar manner:

      def x = '123'
      for (int i=0; i<5;i++) { x = new HashSet() }
      x.toInteger()
      
      def x = '123'
      while (false) { x = new HashSet() }
      x.toInteger()
      
      def x = '123'
      def cond = false
      cond?(x = new HashSet()):3
      x.toInteger()
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: