You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Andres Almiray (Jira)" <ji...@apache.org> on 2020/02/12 19:10:00 UTC
[jira] [Created] (GROOVY-9396) Captured arguments in closures are
not annotated with @Generated
Andres Almiray created GROOVY-9396:
--------------------------------------
Summary: Captured arguments in closures are not annotated with @Generated
Key: GROOVY-9396
URL: https://issues.apache.org/jira/browse/GROOVY-9396
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.5.9, 3.0.0
Reporter: Andres Almiray
Assignee: Andres Almiray
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
{code:java}
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'
}
}
{code}
Is compiled to the following bytecode
{code:java}
...
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);
}
...
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)