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

Groovyc: anonymous class in static method cannot access its fields without "this"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.8
    • 2.5.8, 3.0.0-rc-1
    • None
    • None
    • JAVA_VERSION="1.8.0_111"
      OS_NAME="Windows"
      OS_VERSION="5.2"
      OS_ARCH="amd64"

    Description

      import groovy.transform.CompileStatic
      
      @CompileStatic // also happens without it
      final class TestCase {
      
          static thisShouldCompile() {
      
              Object o = new Object() {
      
                  int inaccessible
      
                  @Override
                  int hashCode() {
                      inaccessible++ // succeeds when qualified with "this"
                      return super.hashCode()
                  }
              }
          }
      
          static void main( String... args ) {
              thisShouldCompile()
              System.out.println( "Success" )
          }
      }
      

      Could be related to GROOVY-7020

      Attachments

        Activity

          People

            Unassigned Unassigned
            hussdl Daniel Huss
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: