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

for-loop type declaration does not work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.7
    • 1.8-beta-4
    • None
    • None
    • Groovy 1.7.7 on Windows XP x86

    Description

      The type declaration of the iterator variable in a for-loop seems to be ignored:

      List l = ['aaa'] // contains one String
      try {
          for (Integer i in l) { // iterator declared Integer (not assignable from String!)
              // GroovyCastException expected in assignment to i in the previous line
              assert false // we should not get this far, expected GroovyCastException
          }
      }
      catch (org.codehaus.groovy.runtime.typehandling.GroovyCastException e) {
          assert true // expected exception
      }
      

      Exception thrown
      07.02.2011 17:33:40 org.codehaus.groovy.runtime.StackTraceUtils sanitize

      WARNUNG: Sanitizing stacktrace:

      Assertion failed:

      assert false // we should not get this far, expected GroovyCastException

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            joerg.schreiner Jörg Schreiner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: