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

Captured arguments in closures are not annotated with @Generated

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.0.0, 2.5.9
    • Fix Version/s: 2.5.10, 4.0.0-alpha-1, 3.0.1
    • Component/s: Compiler
    • Labels:
      None

      Description

      When a closure captures arguments, say from an enclosing method, these arguments are exposed via public getters. these getters should be annotated with `@Generated`.

      The following class

      class GroovyClosureClassTarget { // assertEmpty()
          Closure<String> c(String arg ) {
              def closureVar = {
                  arg // assertFullyCovered()
              }
              closureVar // assertFullyCovered()
          }    static void main(String[] args) {
              Closure cls = new GroovyClosureClassTarget().c('var')
              cls() == 'var'
          }
      }
      

      Is compiled to the following bytecode

      ...
      public Closure<String> c(String arg) {
          final Reference arg = new Reference(arg);
          CallSite[] var3 = $getCallSiteArray();    final class _c_closure1 extends Closure implements GeneratedClosure {
              public _c_closure1(Object _outerInstance, Object _thisObject) {
                  CallSite[] var4 = $getCallSiteArray();
                  super(_outerInstance, _thisObject);
              }        
              public Object doCall(Object it) {
                  CallSite[] var2 = $getCallSiteArray();
                  return arg.get();
              }
              // missing annotation here!!  
              public String getArg() {
                  CallSite[] var1 = $getCallSiteArray();
                  return (String)ShortTypeHandling.castToString(arg.get());
              }        
              @Generated
              public Object doCall() {
                  CallSite[] var1 = $getCallSiteArray();
                  return this.doCall((Object)null);
              }
          }    
          Object closureVar = new _c_closure1(this, this);
          return (Closure)ScriptBytecodeAdapter.castToType(closureVar, Closure.class);
      }
      ...
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                aalmiray Andres Almiray
                Reporter:
                aalmiray Andres Almiray
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h