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

STC rejects program when assigning a closure that returns a class field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-beta-2
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.Supplier;
      
      class Main {
          byte x = 1;
      
          void foo() {
              Supplier<Number> y =  () -> x;
              
          }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.java: 8: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.function.Supplier<java.lang.Byte> to: java.util.function.Supplier<java.lang.Number>
       @ line 8, column 31.
                 Supplier<Number> y =  () -> x;
                                       ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Note that if `x` is a local variabled defined in function `foo`, groovyc compiles the program successfully.

      Tested against master

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: