Skip Menu |
Report information
Id: 131290
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: elizabeth <liz [at] dijkmat.nl>
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: is default() doesn't work on attributes
Date: Fri, 12 May 2017 12:04:31 +0200
To: rakudobug [...] perl.org
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Download (untitled) / with headers
text/plain 767b
<lizmat> m: class A { has Int $.a is default(42) }; dd A.new.a # expected to see 42 there, not Int, so feels like "is default" on attrs isn't implemented? <+camelia> rakudo-moar a9a161: OUTPUT: «Int␤» <lizmat> m: my Int $a is default(42); say $a <+camelia> rakudo-moar a9a161: OUTPUT: «42␤» <lizmat> m: class A { has Int $.a is default(42) }; use nqp; dd nqp::getattr(A.CREATE,A,q/$!a/).VAR.default # oddly enough, it appears to be set <+camelia> rakudo-moar a9a161: OUTPUT: «42␤» <lizmat> class A { has Int $!a is default(42); method a() is raw { $!a } }; dd A.CREATE.a # but this doesn't :-( <+camelia> rakudo-moar a9a161: OUTPUT: «Int $!a = Int␤» This doesn’t seem to be cause by BUILD, as the .CREATE part bypasses all of that. Weird!
Download (untitled) / with headers
text/plain 385b
On Fri, 12 May 2017 03:04:46 -0700, elizabeth wrote: Show quoted text
> <lizmat> m: class A { has Int $.a is default(42) }; dd A.new.a > # expected to see 42 there, not Int, so feels like "is default" on > attrs isn't implemented?
It does work if you add =Nil class A { has Int $.a is rw is default(42) = Nil }; dd A.new.a; # 42 $_ = A.new(:a(34)); .a = Nil; dd .a; # 42
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
To: perl6-bugs-followup [...] perl.org
Date: Sat, 13 May 2017 08:06:40 +0200
Subject: Re: [perl #131290] is default() doesn't work on attributes
Download (untitled) / with headers
text/plain 717b
Show quoted text
> On 13 May 2017, at 03:45, Brad Gilbert via RT <perl6-bugs-followup@perl.org> wrote: > On Fri, 12 May 2017 03:04:46 -0700, elizabeth wrote:
>> <lizmat> m: class A { has Int $.a is default(42) }; dd A.new.a >> # expected to see 42 there, not Int, so feels like "is default" on >> attrs isn't implemented?
> > It does work if you add =Nil > > class A { has Int $.a is rw is default(42) = Nil }; > dd A.new.a; # 42 > $_ = A.new(:a(34)); > .a = Nil; > dd .a; # 42
The whole reason for me to look at this, was to prevent the explicit initialization, done by BUILDALL. If you don’t, it still doesn’t work: $ 6 'class A { has Int $.a is rw is default(42) = Nil }; say A.CREATE.a' (Int) :-(


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org