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

Extend multi-assignment type checking to Range expressions

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • None
    • None

    Description

      The following code runs fine without TypeChecked but fails in static checking mode.

      @groovy.transform.TypeChecked
      def method() {
          def (x, y, z) = 1..3
          assert "$x $y $z" == '1 2 3'
      }
      
      method()
      

      The error is:

      [Static type checking] - Multiple assignments without list or tuple on the right-hand side are unsupported in static type checking mode
      

      The workaround is to replace the range on the RHS of the multi-assignment with a list:

        def (x, y, z) = [1, 2, 3]
      

      But since we know the range expression, we can do further checking.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment