Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.15, 3.0.0-alpha-3, 2.5.2
-
None
-
None
-
Groovy Version: 3.0.0-alpha-3 JVM: 1.8.0_171 Vendor: Oracle Corporation OS: Mac OS X
Description
The following code throws an error at runtime:
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()
This is the error I see on Groovy 3.0.0-alpha-3 (same as previous versions):
groovy.lang.MissingPropertyException: No such property: n for class: Tish
This is expected to work because, outside of traits, it does: this runs successfully:
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()