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

Cannot use array if it is assigned twice

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.7, 2.4.0-beta-3
    • 2.3.9, 2.4.0-rc-1
    • Static compilation
    • None

    Description

      Groovy code:

      @groovy.transform.CompileStatic
      void test() {
          Number[] ary
          ary = [1] as Integer[]
          ary[0] = null
          ary = [1] as Number[]
      }
      test()
      

      This generates this error message.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      C:\Users\Yu\Desktop\test2.groovy: 5: [Static type checking] - Cannot call <T,U extends T> java.lang.Integer[]#putAt(int, U) with arguments [int, java.lang.Object]
       @ line 5, column 5.
             ary[0] = null
             ^
      

      If I remove "ary = [1] as Number[]" the compile error does not happen.
      I think this is a flow typing bug.


      Also If I change this code from "ary[0] = null" to "ary[0] = 2",

      @groovy.transform.CompileStatic
      void test() {
          Number[] ary
          ary = [1] as Integer[]
          ary[0] = 2
          ary = [1] as Number[]
      }
      test()
      

      the error message is this.

      Caught: java.lang.IllegalAccessError: tried to access class org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport$ObjectArrayStaticTypesHelper from class test2
      java.lang.IllegalAccessError: tried to access class org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport$ObjectArrayStaticTypesHelper from class test2
              at test2.test(test2.groovy:5)
              at test2.run(test2.groovy:8)
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            yukoba Yu Kobayashi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: