You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Renato Athaydes (JIRA)" <ji...@apache.org> on 2018/10/01 18:22:00 UTC
[jira] [Updated] (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 ]
Renato Athaydes updated GROOVY-8820:
------------------------------------
Summary: Closure inside trait cannot use Closure's delegate variables (was: Closure inside trait does cannot use Closure's delegate variables)
> 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
> 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
(v7.6.3#76005)