develooper Front page | perl.perl6.compiler | Postings from July 2012

a method with the name of an attribute creates infinite loop

Thread Next
From:
Gabor Szabo
Date:
July 12, 2012 23:18
Subject:
a method with the name of an attribute creates infinite loop
Message ID:
CABe4FJA9mTNFbrxiAmTZJk0k7hAraVY=4k6ZR==9MmcLzcRpCQ@mail.gmail.com
use v6;

class X {
   has @.add;
   method add {
      say 'before';
      @.add.push( 42 );
      say 'ever after';
   }
}

my $v = X.new;
$v.add;
say "hi";

Accidentally I created the same method name as one of the attributes.

This will print 'before'   a *lot* of times and never get to 'ever after'.

I am not sure what should happen,
but maybe Rakudo should notice that and give an error message.

regards
   Gabor

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About