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

DefaultGroovyMethods.sum(Iterable) is not CompileStatic aware

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • 2.4.4, 2.4.5
    • None
    • groovy-jdk
    • None
    • JDK 1.8.0_51/win32

    Description

      @groovy.transform.CompileStatic
      void bug() {
          int a = [1,2,3].sum()
      }
      

      The code above works correctly with CompileDynamic, but CompileStatic will produce the following error:

      [Static type checking] - Cannot assign value of type java.lang.Object to variable of type int
      

      Seems to be a problem of DefaultGroovyMethods.sum(Iterable).

      I think it just need to be changed from

      public static Object sum(Iterable self)
      

      to

      public static <T> T sum(Iterable<T> self)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            biafab Fabiano Biagini
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: