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

array length is not correct with CompileStatic'd code.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.1
    • 2.0.2
    • Compiler
    • None
    • Mac OX X 10.7.4
      java version "1.7.0_04"
      Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

    Description

      In following code, the second assert fails.

      @groovy.transform.CompileStatic
      def main(){
        boolean[] flags1 = new boolean[10]
        assert flags1.class == boolean[]
        assert flags1.size() == 10 // OK
      
        def flags2 = new boolean[10] // dynamic type
        assert flags2.class == boolean[]
        assert flags2.size() == 10 // LHS is 1(not expected)
      }
      
      main()
      

      I tried also int[] instead of boolean[]

      @groovy.transform.CompileStatic
      def main(){
        int[] flags1 = new int[10]
        assert flags1.class == int[]
        assert flags1.size() == 10 // OK
      
        def flags2 = new int[10]  // dynamic type
        assert flags2.class == int[]
        assert flags2.size() == 10 // Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[I@3b845321' with class '[I' to class 'int'
      }
      
      main()
      
      

      When remove CompileStatic annotation, above are no problem.
      Using @TypeChecked instead of @CompileStatic claims nothing.
      I think it is a problem about the code generated by CompileStatic or type inference.

      Attachments

        Activity

          People

            melix Cédric Champeau
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: