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

Inconsistency in multiple assignment with single variable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.0-alpha-1, 2.4.10
    • Fix Version/s: 2.6.0-alpha-1
    • Component/s: None
    • Labels:
      None

      Description

      def a
      def b = [1]
      
      a = b
      println "${a} : ${a.class}" // [1] : class java.util.ArrayList
      (a) = b
      println "${a} : ${a.class}" // 1 : class java.lang.Integer
      ((a)) = b
      println "${a} : ${a.class}" // [1] : class java.util.ArrayList
      

      This is confusing. Here are options:
      1. ((a)) = b should be failed to parse.
      2. ((a)) = b should behave like (a) = b, i.e. number of parentheses should not matter.
      3. ((a)) = b and (a) = b should behave like a = b. This will match the following case also:

      class A { def myField }
      
      def a = new A()
      def b = [1]
      
      a.myField = b
      assert a.myField == [1]
      
      (a.myField) = b
      assert a.myField == [1]
      
      ((a.myField)) = b
      assert a.myField == [1]
      

        Activity

        Hide
        blackdrag Jochen Theodorou added a comment -

        I think ((a))=b should not parse

        Show
        blackdrag Jochen Theodorou added a comment - I think ((a))=b should not parse
        Hide
        daniilo Daniil Ovchinnikov added a comment -

        Jochen Theodorou then ((a.myField)) = b should not be parsed too.

        Show
        daniilo Daniil Ovchinnikov added a comment - Jochen Theodorou then ((a.myField)) = b should not be parsed too.
        Hide
        daniel_sun Daniel Sun added a comment -
        Show
        daniel_sun Daniel Sun added a comment - Fixed by https://github.com/apache/groovy/commit/23c6cdc6902df8ff58a85e28651ffff7b58473d0 Thanks for your reporting the issue

          People

          • Assignee:
            daniel_sun Daniel Sun
            Reporter:
            daniilo Daniil Ovchinnikov
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development