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

Update Multiple Assignment feature to allow arbitrary expressions, not just simple variables

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.6.3
    • None
    • Compiler
    • None

    Description

      Consider this simple test:

      def f()

      { [1, 2] }

      class X

      { def a def b }

      // OK
      def (int a, int b) = f()
      def (aok, bok) = f()

      // error: expecting ')', found ',' at line: 16, column: 5
      def x = new X()
      (x.a, x.b) = f()
      (x.@a, x.@b) = f()

      println "$x.a, $x.b"

      I found this error surprising...I would like to see fields/arrays/etc. (general lvalues) supported.

      The current "Multiple simple variable initialisation" facility leads to surprise and cumbersome code, as in what got me fired up:

      def (int centerX, int centerY) = findCenter(model.boundingPolygon)
      model.boundingPolygonCenterX = centerX
      model.boundingPolygonCenterY = centerY

      Strikes ME as being appropriate for 1.7...

      Attachments

        Activity

          People

            Unassigned Unassigned
            alpheratz alpheratz
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: