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

Owner: Nobody
Requestors: bri [at] abrij.org
Cc:
AdminCc:

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



Date: Fri, 19 Jun 2015 01:43:57 -0400
Subject: attributive parameters alter object during any bind, not just invoke
To: rakudobug [...] perl.org
From: bri <bri [...] abrij.org>
Download (untitled) / with headers
text/plain 656b
# Attributive parameters can load themselves into objects during # seemingly innocent smartmatches, and probably other places where # is_bindable semantics are intended. perl6 -e 'class a { has $.a; method foo { say so (self,2) ~~ :(\self: $!a); self.a.say } }; a.new.foo()' True 2 #...like multidispatch tests $ for i in 1 2 3 4 5; do perl6 -e 'my $*r; class A { has $.a = 4; multi method foo (A $b (:$!a), Int $c where { $*r //= Bool.pick }) { 42.say }; multi method foo (A $b, Int $c) { self.a.say } }; my A $a .= new; my A $b .= new(:a(2)); $a.foo($b,1);' ; done 2 2 42 2 42 # (above, $a.a should only be 2 when 42 is printed, should otherwise be 4.)
Date: Sun, 2 Aug 2015 16:29:56 -0400
From: bri <bri [...] abrij.org>
Subject: Re: [perl #125437] attributive parameters alter object during any bind, not just invoke
To: perl6 via RT <perl6-bugs-followup [...] perl.org>
Download (untitled) / with headers
text/plain 135b
Please also see the conversation at: http://irclog.perlgeek.de/perl6/2015-08-02#i_10992867 ...when deciding how to fix this one.
Download (untitled) / with headers
text/plain 1.5k
More investigation, done while trying to get the desired behavior mentioned in the IRC conversation: It appears that just mentioning an attribute in a BUILD submethod is enough to prevent it from being assigned its default after the custom BUILD is run; you don't have to actually assign to it: (12:58:54 PM) skids: m: class A { has $.a = 42.say; submethod BUILD { } }.new.a.perl.say; (12:58:55 PM) camelia: rakudo-moar 97e47a: OUTPUT«42␤Bool::True␤» (12:59:09 PM) skids: m: class A { has $.a = 42.say; submethod BUILD { $!a; } }.new.a.perl.say; (12:59:10 PM) camelia: rakudo-moar 97e47a: OUTPUT«Any␤» ...except for native attributes: (01:15:36 PM) skids: m: class A { has int $.a = { 42.say; 43 }(); submethod BUILD () { } }.new().a.perl.say; (01:15:36 PM) camelia: rakudo-moar 97e47a: OUTPUT«42␤43␤» (01:17:06 PM) skids: m: class A { has int $.a = { 42.say; 43 }(); submethod BUILD () { $!a; } }.new().a.perl.say; (01:17:07 PM) camelia: rakudo-moar 97e47a: OUTPUT«42␤43␤» ...which may or may not be related to the following, which results from some cheating WRT figuring out whether a native attribute was touched: (01:19:22 PM) skids: m: class A { has int $.a = { 42.say; 43 }(); }.new(:a(1)).a.perl.say; (01:19:22 PM) camelia: rakudo-moar 97e47a: OUTPUT«1␤» (01:19:27 PM) skids: m: class A { has int $.a = { 42.say; 43 }(); }.new(:a(0)).a.perl.say; (01:19:28 PM) camelia: rakudo-moar 97e47a: OUTPUT«42␤43␤» ...which makes it a bit difficult to set a native attribute to its "undefined" value if it has a default.
Just to add, a partial fix is in PR#539 though there is a good chance it is bitrotted by now.


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