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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.8
    • Fix Version/s: 2.5.8, 3.0.0-rc-1
    • Component/s: None
    • Labels:
      None
    • Environment:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: