[ https://issues.apache.org/jira/browse/GROOVY-9386?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun resolved GROOVY-9386. -------------------------------- Fix Version/s: 3.0.6 4.0.0-alpha-1 Resolution: Fixed > Field initialized in a trait using tap doesn't work correctly > ------------------------------------------------------------- > > Key: GROOVY-9386 > URL: https://issues.apache.org/jira/browse/GROOVY-9386 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.5.9, 3.0.0-rc-3 > Reporter: Matthias Kiefer > Assignee: Eric Milles > Priority: Minor > Fix For: 4.0.0-alpha-1, 3.0.6 > > Time Spent: 20m > Remaining Estimate: 0h > > The following code > {code:groovy} > class Foo { > int bar > } > trait TestTrait { > def foo = new Foo().tap{ > bar = 1 > } > } > class SomeClass implements TestTrait { > } > new SomeClass() > {code} > fails with the following error: > {noformat} > Caught: groovy.lang.MissingPropertyException: No such property: bar for > class: SomeClass > Possible solutions: foo > groovy.lang.MissingPropertyException: No such property: bar for class: > SomeClass > Possible solutions: foo > at TestTrait$Trait$Helper$__init__closure1.doCall(scratch.groovy:8) > at TestTrait$Trait$Helper.$init$(scratch.groovy:7) > at SomeClass.<init>(scratch.groovy) > at scratch.run(scratch.groovy:16) > {noformat} > if using the following code in the tap makes it work correctly: > {code:groovy} > trait TestTrait { > def foo = new Foo().tap{ > it.bar = 1 > } > } > {code} > Also when used in a class directly, it works also correctly: > {code:groovy} > class SomeClass { > def foo = new Foo().tap{ > bar = 1 > } > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)