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

STC is unable to resolve variable in closure

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Information Provided
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.Supplier;
      
      class B {
        Supplier<Integer> m2() {
          final def x = 1
          { -> x + 1 }
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 5: [Static type checking] - Cannot find matching method int#call(groovy.lang.Closure). Please check if the declared type is correct and if the method exists.
       @ line 5, column 19.
             final def x = 1
                           ^test.groovy: 6: [Static type checking] - The variable [x] is undeclared.
       @ line 6, column 10.
             { -> x + 1 }
                  ^test.groovy: 5: [Static type checking] - Cannot return value of type java.lang.Object on method returning type java.util.function.Supplier<java.lang.Integer>
       @ line 5, column 5.
             final def x = 1
             ^3 errors
      
      

      Expected behaviour

      Compile 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: