You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Matthias Kiefer (Jira)" <ji...@apache.org> on 2020/02/06 16:35:00 UTC

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

Matthias Kiefer created GROOVY-9386:
---------------------------------------

             Summary: 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: 3.0.0-rc-3, 2.5.9
            Reporter: Matthias Kiefer


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)