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:20:00 UTC
[jira] [Created] (GROOVY-8820) Closure inside trait does cannot use
Closure's delegate variables
Renato Athaydes created GROOVY-8820:
---------------------------------------
Summary: Closure inside trait does 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.5.2, 3.0.0-alpha-3, 2.4.15
Environment: Groovy Version: 3.0.0-alpha-3 JVM: 1.8.0_171 Vendor: Oracle Corporation OS: Mac OS X
Reporter: Renato Athaydes
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)