Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5989 Inner Class Issues
  3. GROOVY-5961

Variable scope not checked properly for AIC in static method

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 3.0.0-beta-1, 2.5.7
    • Component/s: Compiler
    • Labels:
      None

      Description

      The following code will fail:

      static void foo() {
          new LinkedList() {
              int index
              Object get(int i) { super.get(index++) }
          }
      }
      

      The error is:

      Apparent variable 'index' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes:
      You attempted to reference a variable in the binding or an instance variable from a static context.
      You misspelled a classname or statically imported field. Please check the spelling.
      You attempted to use a method 'index' but left out brackets in a place not allowed by the grammar.
       at line: 5, column: 39
      

      But obviously, index is not accessed from a static context here.

        Attachments

        1. VariableScopeVisitor.java
          22 kB
          Eric Milles

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              melix C├ędric Champeau
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: