You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Gerald Wiltse <je...@gmail.com> on 2016/02/10 16:52:45 UTC
Behavior of .with() inside Trait
This example returns the error inside the with closure:
"No such property: cow for class:Bar"
It seems .with() in a trait does not resolve the way it "normally" does.
trait Foo {
def action() {
println binding.cow
binding.with {
println cow
}
}
}
class Bar implements Foo {
Binding binding = new Binding()
}
def myBar = new Bar()
myBar.binding.cow = "says moo"
myBar.action()
If anyone has any insight, it would be helpful.
Gerald R. Wiltse
jerrywiltse@gmail.com
Re: Behavior of .with() inside Trait
Posted by Gerald Wiltse <je...@gmail.com>.
Thanks for the input Schalk,
Can anyone else indicate if this looks like a bug, or an intended
behavior? If so, I can submit the bug.
Gerald R. Wiltse
jerrywiltse@gmail.com
On Wed, Feb 10, 2016 at 11:04 AM, Schalk Cronjé <ys...@gmail.com> wrote:
> The interesting thing about this for me is that for
>
> binding.with {
> println cow
> }
>
> the generated code is
>
> public static java.lang.Object action(Foo $self) {
> return $self .binding.with({
> return $self.println( $self .cow)
> }.rehydrate($self, $self, $self))
> }
>
> but for
>
> println binding.cow
>
> the generated code is
>
> public static java.lang.Object action(Foo $self) {
> return $self.println( $self .binding.cow)
>
> }
>
>
> On 10/02/2016 16:52, Gerald Wiltse wrote:
>
> This example returns the error inside the with closure:
>
> "No such property: cow for class:Bar"
>
> It seems .with() in a trait does not resolve the way it "normally" does.
>
>
> trait Foo {
> def action() {
> println binding.cow
> binding.with {
> println cow
> }
> }
> }
>
> class Bar implements Foo {
> Binding binding = new Binding()
> }
>
>
> def myBar = new Bar()
> myBar.binding.cow = "says moo"
> myBar.action()
>
>
> If anyone has any insight, it would be helpful.
>
>
> Gerald R. Wiltse
> jerrywiltse@gmail.com
>
>
>
> --
> Schalk W. Cronjé
> Twitter / Ello / Toeter : @ysb33r
>
>
Re: Behavior of .with() inside Trait
Posted by Schalk Cronjé <ys...@gmail.com>.
The interesting thing about this for me is that for
binding.with {
println cow
}
the generated code is
public static java.lang.Object action(Foo $self) {
return $self .binding.with({
return $self.println( $self .cow)
}.rehydrate($self, $self, $self))
}
but for
println binding.cow
the generated code is
public static java.lang.Object action(Foo $self) {
return $self.println( $self .binding.cow)
}
On 10/02/2016 16:52, Gerald Wiltse wrote:
> This example returns the error inside the with closure:
>
> "No such property: cow for class:Bar"
>
> It seems .with() in a trait does not resolve the way it "normally" does.
>
>
> trait Foo {
> def action() {
> println binding.cow
> binding.with {
> println cow
> }
> }
> }
>
> class Bar implements Foo {
> Binding binding = new Binding()
> }
>
>
> def myBar = new Bar()
> myBar.binding.cow = "says moo"
> myBar.action()
>
>
> If anyone has any insight, it would be helpful.
>
>
> Gerald R. Wiltse
> jerrywiltse@gmail.com <ma...@gmail.com>
>
--
Schalk W. Cronjé
Twitter / Ello / Toeter : @ysb33r