What will happen if the attribute's names are the same but declared with different keyword?

0 views
Skip to first unread message

Yiyi Hu

unread,
Aug 17, 2005, 3:33:35 PM8/17/05
to perl6-l...@perl.org
class T
{
has $.a =1;
my $.a=2;
};
my T $o .= new;
$o.a().say;

What the result will be please?
1 or 2?
Or an error?

Thanks,
Xinming

Larry Wall

unread,
Aug 17, 2005, 3:38:45 PM8/17/05
to perl6-l...@perl.org
On Thu, Aug 18, 2005 at 03:33:35AM +0800, Yiyi Hu wrote:
: class T

: {
: has $.a =1;
: my $.a=2;
: };
: my T $o .= new;
: $o.a().say;
:
: What the result will be please?
: 1 or 2?
: Or an error?

Definitely a compile-time error. You can't declare the same lexical
name even if the declarator is different. But even if that were
allowed, you also may not declare two attributes that generate an
accessor of the same name.

Larry

Reply all
Reply to author
Forward
0 new messages