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

Multiple assignment from Iterator skips every other element

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.5
    • 5.0.0-alpha-1
    • groovy-runtime
    • None

    Description

      If you try to assign multiple variables from an iterator Groovy will skip every other value.

      Example:

      final list = [1,2,3]
      final iter = list.iterator()
      
      final def (a,b,c) = list
      final def (d,e,f) = iter
      
      assert "$a $b $c" == "$d $e $f"
      

      Result:

      Assertion failed: 
      
      assert "$a $b $c" == "$d $e $f"
               |  |  |  |    |  |  |
               1  2  3  |    1  3  null
                        false
      

      The expected behavior is either that the assertion succeeds, or the assignment to (d,e,f) fails outright.

      If this is fixed it would also be nice if any Iterable could be used on the RHS.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              justin.piper@gmail.com Justin Piper
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: