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/07/31 18:48:00 UTC

[jira] [Assigned] (GROOVY-9386) Field initialized in a trait using tap doesn't work correctly

     [ https://issues.apache.org/jira/browse/GROOVY-9386?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles reassigned GROOVY-9386:
-----------------------------------

    Assignee: Eric Milles

> 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
>
> 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)