You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/08/10 13:55:00 UTC
[jira] [Resolved] (GROOVY-8820) Closure inside trait cannot use
Closure's delegate variables
[ https://issues.apache.org/jira/browse/GROOVY-8820?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-8820.
---------------------------------
Fix Version/s: 3.0.6
4.0.0-alpha-1
Resolution: Fixed
> 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
> Fix For: 4.0.0-alpha-1, 3.0.6
>
>
> 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)