Skip Menu |
Report information
Id: 131387
Status: resolved
Priority: 0/
Queue: perl6

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

Severity: (no value)
Tag: testneeded
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) :-(
Subject: `is default` value not applied to attributes by default
Download (untitled) / with headers
text/plain 308b
$z is `Nil` without my having to assign anything, while `$!z` is Any. To make `$!z` Nil I also have to assign Nil to it: <Zoffix___> m: my $z is default(Nil); dd $z; class Foo { has $!z is default(Nil); method x { dd $!z } }.new.x <camelia> rakudo-moar 0c5fe5: OUTPUT: «Nil $z = Nil␤Any $!z = Any␤»
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 558b
On Sat, 27 May 2017 19:35:53 -0700, cpan@zoffix.com wrote: Show quoted text
> $z is `Nil` without my having to assign anything, while `$!z` is Any. > To make `$!z` Nil I also have to assign Nil to it: > > <Zoffix___> m: my $z is default(Nil); dd $z; class Foo { has $!z is > default(Nil); method x { dd $!z } }.new.x > <camelia> rakudo-moar 0c5fe5: OUTPUT: «Nil $z = Nil␤Any $!z = Any␤»
Seems fixed, test needed. 13:56 < jnthn> m: class Foo { has $!z is default(Nil); method x { dd $!z } }.new.x 13:56 <+camelia> rakudo-moar 760530: OUTPUT: «Nil $!z = Nil␤»
Download (untitled) / with headers
text/plain 693b
On Tue, 12 Sep 2017 06:57:13 -0700, jnthn@jnthn.net wrote: Show quoted text
> On Sat, 27 May 2017 19:35:53 -0700, cpan@zoffix.com wrote:
> > $z is `Nil` without my having to assign anything, while `$!z` is Any. > > To make `$!z` Nil I also have to assign Nil to it: > > > > <Zoffix___> m: my $z is default(Nil); dd $z; class Foo { has $!z > > is > > default(Nil); method x { dd $!z } }.new.x > > <camelia> rakudo-moar 0c5fe5: OUTPUT: «Nil $z = Nil␤Any $!z = Any␤»
> > Seems fixed, test needed. > > 13:56 < jnthn> m: class Foo { has $!z is default(Nil); method x { dd > $!z } }.new.x > 13:56 <+camelia> rakudo-moar 760530: OUTPUT: «Nil $!z = Nil␤»
Tests done in roast 563f957d06, so resolving.


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