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

Compile error when accessing a public field inside a closure

    XMLWordPrintableJSON

Details

    Description

      The following code works fine in 2.5.6 but breaks in 2.5.7:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Class1 {
          public String prop1
      }
      
      @CompileStatic
      class Class2 {
      
          String doThing(Class1 c1) {
              return 'something'.with {
                  println c1.prop1
                  return it
              }
          }
      }
      
      new Class2().doThing(new Class1(prop1: 'value1'))
      

      The error is

      Access to Class1#c1 is forbidden at line: -1, column: -1
      

      Note that if you remove the `public` modifier from `Class1.prop1` the code is fine. Likewise, if you take `@CompileStatic` off of `Class2`, everything works fine.

      Attachments

        Activity

          People

            paulk Paul King
            jbellassai John Bellassai
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h
                1h