You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2020/02/13 17:26:00 UTC
[jira] [Resolved] (GROOVY-9396) Captured arguments in closures are
not annotated with @Generated
[ https://issues.apache.org/jira/browse/GROOVY-9396?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun resolved GROOVY-9396.
--------------------------------
Fix Version/s: 3.0.1
4.0.0-alpha-1
2.5.10
Resolution: Fixed
> 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: 3.0.0, 2.5.9
> Reporter: Andres Almiray
> Assignee: Andres Almiray
> Priority: Minor
> Fix For: 2.5.10, 4.0.0-alpha-1, 3.0.1
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> 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)