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

Owner: Nobody
Requestors: davidnmfarrell [at]
masak <cmasak [at]>

Severity: (no value)
  • Bug
  • testcommitted
Platform: (no value)
Patch Status: (no value)
VM: (no value)

Date: Sat, 26 Sep 2015 15:43:12 +0200
Subject: [BUG] Defining a Proxy with methods instead of subs leads to surprising results in Rakudo
From: Carl Mäsak <cmasak [...]>
To: rakudobug [...]
moritz++' gist inlined for your convenience: our $count = 0; class MagicVal { has Int $.constant; has Int $.varies = 0; method varies is rw { $count++; return-rw # note that FETCH and STORE cannot go through the accessors # of $.varies again, because that would lead to infinite # recursion. Use the actual attribute here instead FETCH => method () { $!varies }, STORE => method ($new) { $!varies = $new + 1 }, ); } } my $mv =, :varies(6)); say $mv.varies.VAR.^name; # Proxy say $mv.varies.^name; # Method <moritz> m: <camelia> rakudo-moar 0132b6: OUTPUT«Proxy␤Method␤» <moritz> why does the last line print Method here? <moritz> and not Int? <masak> good question. <masak> does just `$mv.varies` print 6? <moritz> masak: no, it says <anon> <masak> sounds wrong to me. <ShimmerFairy> moritz: Well, it's because you mapped those keys to Method objects, no? <masak> ShimmerFairy: isn't that the way you implement a Proxy, though? <masak> you give FETCH and STORE a callable each. doesn't mean they get exposed. <ShimmerFairy> masak: I've never seen the method keyword used with it, I don't think. Just plain closures <masak> ShimmerFairy: the presence of the `method` keyword there is practically irrelevant. <moritz> ShimmerFairy: the 'method' keyword just means they get an invocant <masak> m: my &c1 = sub ($obj, $x) { say "$obj: $x" }; my &c2 = method ($obj: $x) { say "$obj: $x" }; c1("OH HAI", 42); "OH HAI".&c2(42) <camelia> rakudo-moar 0132b6: OUTPUT«OH HAI: 42␤OH HAI: 42␤» <masak> ShimmerFairy: ^ <masak> it's only a matter of intent, not a matter of differing semantics. <moritz> huh <moritz> but changing it to a sub instead helps indeed <moritz> wtf? <masak> ok, bug * masak submits rakudobug <masak> it's probably special-cased where it oughtn't be <jdv79> i think i ran into that a few months ago and just ignored it when someone showed me the working one <masak> let's fix it instead :P
FWIW, fudged tests are in S12-attributes/mutators.t

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

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