Skip Menu |
Report information
Id: 126680
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: rob [at] hoelz.ro
Cc:
AdminCc:

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



Subject: Referring to an attribute in BUILD prevents it from getting its default value
Download (untitled) / with headers
text/plain 1.4k
Excerpt from #perl6: 22:42 hoelzro if the default logic happens after BUILD, then $!server is Str because BUILD doesn't set it up via its signature 22:43 m: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD(:$!name) { say $!age } }; say Person.new(:name<Rob>) 22:43 camelia rakudo-moar d410e3: OUTPUT«(Any)␤Person.new(name => "Rob", age => Any)␤» ... 22:43 hoelzro m: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD() { say $!age } }; say Person.new(:name<Rob>) 22:43 camelia rakudo-moar d410e3: OUTPUT«(Any)␤Person.new(name => "John", age => Any)␤» ... 22:43 Juerd Right, but that would mean that I can't use any of the defaulting logic if I want other stuff to happen at initialization, using those defaults... 22:43 hoelzro hmm...that's interesting 22:43 m: class Person { has $.name = 'John'; has $.age = 21; submethod BUILD() { } }; say Person.new(:name<Rob>) 22:43 camelia rakudo-moar d410e3: OUTPUT«Person.new(name => "John", age => 21)␤» 22:43 Juerd I can only imagine that this is an extremely common use case. ... 22:44 hoelzro it looks like referring to any attributes in BUILD circumvents their defaulting logic, which seems...odd. ... 22:44 Juerd I could just add the defaults to BUILD's signature, but it's so nice to have them all in one place :( 22:44 hoelzro Juerd: I think that's a rakudobug


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