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

False positive variable scoping error when using AIC in combination with logging AST transform

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 2.3.2
    • 2.3.3
    • None
    • None

    Description

      Compiling this code:

      @Grab('ch.qos.logback:logback-classic:1.0.13')
      @groovy.util.logging.Slf4j
      class MyClass {
          static myMethod() {
              String message = 'hello'  // internal param name p1 from InnerClassVisitor#visitConstructorCallExpression
              String audience = 'world' // p2
              new Runnable() {
                  void run() {
                      println "$message $audience"
                  }
              }
          }
      }
      MyClass.myMethod().run()
      

      Gives this error message:

      2 compilation errors:
      
      Apparent variable 'p2' 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 'p2' but left out brackets in a place not allowed by the grammar.
       at line: -1, column: -1
      
      Apparent variable 'p1' 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 'p1' but left out brackets in a place not allowed by the grammar.
       at line: -1, column: -1
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            paulk Paul King
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: