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

SC: cast exception for private property access from lambda

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.0.10, 4.0.0-rc-1
    • None
    • None

    Description

      Consider the following:

      import java.util.function.Supplier
      
      @groovy.transform.CompileStatic
      class C {
        private String getX() { 'x' }
        void test() {
          Supplier<String> s = () -> x // GroovyCastException: Cannot cast object 'class C' with class 'java.lang.Class' to class 'C'
          print s.get()
        }
      }
      
      new C().test()
      

      If variable expression "x" is replaced by "getX()" this runs successfully. Also works if lambda is replaced by closure. And not compile static works too.

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: