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

Can't use empty range on array with @CompileStatic

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

Details

    Description

      This script fails:

      testMethod()
      
      @groovy.transform.CompileStatic
      def testMethod() {
          def root = new ConfigObject()
          def list = ["1", "2", "3", "4"] as String[]
      
          assert list[0..<0] == []
          assert list[0..<-1] == ["1", "2", "3"]
          println list
      }
      

      The error is:

      Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '0..<0' with class 'groovy.lang.EmptyRange' to class 'groovy.lang.IntRange' due to: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method <init>() to invoke from this list:
        public groovy.lang.IntRange#<init>(int, int)
        protected groovy.lang.IntRange#<init>(int, int, boolean)
        public groovy.lang.IntRange#<init>(boolean, int, int)
      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '0..<0' with class 'groovy.lang.EmptyRange' to class 'groovy.lang.IntRange' due to: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method <init>() to invoke from this list:
        public groovy.lang.IntRange#<init>(int, int)
        protected groovy.lang.IntRange#<init>(int, int, boolean)
        public groovy.lang.IntRange#<init>(boolean, int, int)
      	at groovyBugs.testMethod(groovyBugs.groovy:8)
      	at groovyBugs.run(groovyBugs.groovy:1)
      

      Attachments

        Activity

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

          People

            melix Cédric Champeau
            pledbrook Peter Ledbrook
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment