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

Native lambdas with @CompileStatic at method level

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0-alpha-3
    • 3.0.0-alpha-2, 2.6.0-alpha-4
    • None
    • None

    Description

      This code:

      import groovy.transform.CompileStatic
      import java.util.stream.Collectors
      
      @CompileStatic
      class Main {
          static void main(String[] args) {
              assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList())
          }
      }
      

      works and produces a native lambda with the following bytecode within it's doCall method:

      INVOKESTATIC org/codehaus/groovy/runtime/dgmimpl/NumberNumberPlus.plus (Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;
      

      but moving the @compileStatic to the main method only, results in the following error:

      java.lang.NoSuchMethodError: java.lang.Number.plus(Ljava/lang/Number;)Ljava/lang/Number;
      

      and the following bytecode in the doCall method:

      INVOKESTATIC java/lang/Number.plus (Ljava/lang/Number;)Ljava/lang/Number;
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: