[ https://issues.apache.org/jira/browse/GROOVY-8820?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-8820: ----------------------------------- Assignee: Eric Milles > Closure inside trait cannot use Closure's delegate variables > ------------------------------------------------------------ > > Key: GROOVY-8820 > URL: https://issues.apache.org/jira/browse/GROOVY-8820 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.15, 3.0.0-alpha-3, 2.5.2 > Environment: Groovy Version: 3.0.0-alpha-3 JVM: 1.8.0_171 Vendor: > Oracle Corporation OS: Mac OS X > Reporter: Renato Athaydes > Assignee: Eric Milles > Priority: Major > > The following code throws an error at runtime: > > {code:java} > trait T { > def doIt() { > return { > n = 1 > } > } > } > class Delegate { > int n > } > > class Tish implements T { > def go() { > def closure = doIt() > def d = new Delegate() > closure.delegate = d > closure() > assert d.n == 1 > println "All good!" > } > } > new Tish().go(){code} > > This is the error I see on Groovy 3.0.0-alpha-3 (same as previous versions): > > {code:java} > groovy.lang.MissingPropertyException: No such property: n for class: > Tish{code} > > This is expected to work because, outside of traits, it does: this runs > successfully: > > {code:java} > class T { > def doIt() { > return { > n = 1 > } > } > } > class Delegate { > int n > } > > class Tisha extends T { > def go() { > def closure = doIt() > def d = new Delegate() > closure.delegate = d > closure() > assert d.n == 1 > println "All good!" > } > } > new Tisha().go(){code} > -- This message was sent by Atlassian Jira (v8.3.4#803005)