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

Can't access private static constant from closure, when using @CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.8, 2.1.3
    • Fix Version/s: 2.1.7, 2.2.0-beta-2
    • Component/s: Static compilation
    • Labels:
      None
    • Environment:
      JDK1.7

      Description

      Can not access private static constant from colosure with @CompileStatic
      Code:

      @groovy.transform.CompileStatic
      class A{
        private static final int BASE = 10
        
        void test() {
            def c = { 
                    println BASE
            }
            
            c()
        }  
      }
      
      new A().test()
      

      Output(Without @CompileStatic)

      10
      

      Output(With @CompileStatic)

      1 compilation error:
      
      Access to A#BASE is forbidden at line: -1, column: -1
      

      But this code can work(wrap another closure)

      @groovy.transform.CompileStatic
      class A{
        private static final int BASE = 10
        
        void test() {
            def c = { 
                def c1 = {
                    println BASE
                }
                c1()
            }
            
            c()
        }  
      }
      
      new A().test()
      

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              lusxiao Eddie Lu
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: