Oh, once I found the problem, I just renamed my method. That's ok.
The thing is that it would be nice if Rakudo caught this and told me about it
as I think I am not the last one to make this error.

Anyway, thanks for your solution too!

regards
   Gabor

On Fri, Jul 13, 2012 at 9:20 AM, Tadeusz Sośnierz
<[email protected]> wrote:
> On Friday, July 13, 2012 08:18:19 Gabor Szabo wrote:
>>    method add {
>>       say 'before';
>>       @.add.push( 42 );
>
> If I recall correctly, calling @.add() is the same as @(self.add). Calling a
> method recursively without ending is bound to go into an infinite loop :)
>
> To avoid that you can call push on the attribute, directly, without going
> through the accessor method:
>
> === CODE ===
> class A {
>    has @.add;
>    method add {
>       say 'before';
>       @!add.push( 42 );
>       say 'ever after';
>    }
> }
>
> A.new.add;
>
> Which works without problems:
> === RESULT ===
> before
> ever after
>
>
> Kind regards,
> Tadeusz Sośnierz

Reply via email to