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

Cannot assign closure with long as return type to java.util.function.Function<X, Number>

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.8, 4.0.0-alpha-3
    • Fix Version/s: None
    • Labels:
      None

      Description

      I have the following Groovy program.

      import java.util.function.Function;
      
      @groovy.transform.TypeChecked
      class Main {
        public static void main(String[] args) {
            Function<String, Number> x = { y ->
                final long d = 1;
                return d;
            };
        }
      }
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 6: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.function.Function <java.lang.String, java.lang.Long> to: java.util.function.Function <String, Number>
       @ line 6, column 36.
               Function<String, Number> x = { y ->
                                            ^
      
      1 error
      

      Expected Behavior

      Compile successfully.

      Comment

      Note that javac accepts this program.

      Affected Version

      This programs have been tested with the compiler from the master (commit: 05a39632565bee88949c8db9d56b9f9598321fc2), 4.0.0-alpha-3, and 3.0.8.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              schaliasos Stefanos Chaliasos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: